daily pastebin goal
60%
SHARE
TWEET

PythonTwitterLeassonEP3

Carl123432 Jan 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Today we are going to create a simple calculator in python.
  2. # We are going to use while loops in our code today. The while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.
  3.  
  4. while True: # We have made a while True loop. which will loop until it is told to break out of the loop
  5.     enter = input('Enter the first number: ') # Asked user to insert there first number
  6.     enter1 = input('Enter the mathmatical operator *+/-: ') # Asked user to insert which mathatical Operation they would like.
  7.     enter2 = input('Enter second number: ') # Asked user for third number.
  8.  
  9.     if enter1 in ['*', 'x', 'X']: # Now we are reading the user input and if it includes a piece of text that matches our list. We call the function to times the 2 numbers and we do the same for all 4.
  10.         total_sum = int(enter) * int(enter2)
  11.         print(total_sum)
  12.     elif enter1 == '+':
  13.         total_sum = int(enter) + int(enter2)
  14.         print(total_sum)
  15.     elif enter1 == '/':
  16.         total_sum = int(enter) / int(enter2)
  17.         print(total_sum)
  18.     elif enter1 == '-':
  19.         total_sum = int(enter) - int(enter2)
  20.     elif enter1 in ['stop', 'Stop', 'STOP']: # Now if the user types stop, it will send them to this statment which asks them if thy want to quit.
  21.         stop = input('Are you sure you want to stop the program?: ')
  22.         if stop in ['yes', 'YES', 'y', 'Y']:
  23.             break # If it is a yes, we use the break function. which will return the loop false. and stop the program.
  24.         else:
  25.             print('')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top