Jump to content

Need some help with Python

TheGrim123321

Alright so I've made a simple Python caculator

 

number_1 = int(input('Enter a number: '))
number_2 = int(input('Enter a second number: '))
function = int(input('1. Addition 2. Subtraction 3. Multiplication 4. Division'))
if function == 1 :
   print (number_1+number_2)
if function == 2 :
    print (number_1-number_2)
if function == 3 :
   print (number_1*number_2)
if function == 4 :
   print (number_1/number_2)

 

Now the only language I know besides Python is batch I know that in batch you could  do something like

 

:1

(insert all the code for the math)

 

then after the last print/echo you could add another one that says Would you like to restart? then put goto 1 then it would restart it. So how do I do this in python.

 

TheGrim123321

CPU: I3-4170Cooler: Hyper TX3Mobo:Biostar B85MGMemory: G.Skill Ripjaw 2x4GBStorage: Barracuda 500GBGPU: Zotac GTX660Case: Fractal 1100PSU: Evga 500WMonitors: FHX2153L 21.5"│V193WEJb 19"Keyboard/Mouse: CMStorm DevastorAudio: MonoPrice 8323Microphone: BlueYeti BlackoutOS: MSX(Win10) Quote me or @TheGrim123321 to get my attention.
Link to comment
Share on other sites

Link to post
Share on other sites

you can use a while loop. so first do something like continue = "yes" and then do while continue != "no" [and put the rest of the code in the here and at the end do something like string(input("Do you want to continue (yes/no)"))

Link to comment
Share on other sites

Link to post
Share on other sites

Just put it in a while loop. This will mean that it will run forever.

 

Like:

while continue = True:
  number_1 = int(input('Enter a number: '))
  number_2 = int(input('Enter a second number: '))
  function = int(input('1. Addition 2. Subtraction 3. Multiplication 4. Division'))
  if function == 1 :
     print (number_1+number_2)
  if function == 2 :
      print (number_1-number_2)
  if function == 3 :
     print (number_1*number_2)
  if function == 4 :
     print (number_1/number_2)
  else:
	continue = False

 

Something like this

amnerd  B) Linux enthusiast. 

 

  • CPU: Intel i5 4690k @3.5ghz  Motherboard: MSI U3 Plus Z97 GPU: Radeon R9 270x 2gb OC HDD: WD Green 3tb SDDs: Samsung 120gb, Kingston V300 120gb Case: Fractal Design Define R5 PSU: Corsair V650 Fans: Corsair AF14 x4 CPU cooler: Hyper 212 EVO (Upgrading soon)     
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×