Skip to content

Instantly share code, notes, and snippets.

@mycarta
Last active December 9, 2025 14:17
Show Gist options
  • Select an option

  • Save mycarta/c85a45adc31700f98b4081d2531ee766 to your computer and use it in GitHub Desktop.

Select an option

Save mycarta/c85a45adc31700f98b4081d2531ee766 to your computer and use it in GitHub Desktop.
Naughty calculator
# NB optimized for Python 3
from random import randint
print ('Hello, I am a talking calculator and my name is Jester.')
name = input('What is your name? ')
print ('Hello ' + name.capitalize() + ', nice to meet you!')
while True:
operation = input(name.capitalize() +
', would you like to add or subtract? (enter "a" or "s"; "q" to quit) ')
if operation.lower() =='q':
print('Goodbye ' + name.capitalize())
break
elif operation.lower() =='s' or operation.lower() =='a':
print ('OK, ready.')
input1 = input('Can I have the first number? ')
try:
num1=int(input1)
except ValueError:
print ("That is not a number!")
input1 = input('Can I have the first number? ')
input2 = input('Can I have the second number? ')
try:
num2=int(input2)
except ValueError:
print("That is not a number!")
input2 = input('Can I have the second number? ')
num1=int(input1)
num2=int(input2)
num3 = 0
if (name.lower() == 'olivia'):
rnd1 = randint(1,3)
rnd2 = randint(1,5)
if rnd1 == 3:
num3 = rnd2
if operation.lower() == 'a':
result = num1 + num2 + num3
print (str(num1) + ' + ' + str(num2) + ' = ' + str(result))
elif operation.lower() == 's':
result = (max(num1, num2) - min(num1, num2)) - num3
print (str(max(num1, num2)) + ' - '
+ str(min(num1, num2)) + ' = ' + str(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment