Prank Python Calculator

by matter698 in Circuits > Computers

5162 Views, 6 Favorites, 0 Comments

Prank Python Calculator

newfile.png
Hello! As a novice python programmer, I love to make little programs to annoy my friends. (They love it too. They won't admit it.) I noticed online, that python is only used for useful things, like web apps. There really isn't a good prank python program tutorial out there. Luckily, I am here to change that. Today I will show you how to make a python calculator that gives bad answers!

This tutorial assumes that you have some basic python knowledge, and that you have the python idle on your computer. (I used python 2.7)

Importing the Random Number

import.png
In order to make this work, we need to have a way to give the wrong answer. I could just tell the code to carry out the wrong operation, but that would be too easy. Let's make it use a random number.

To do that, open up the IDLE, and type at the top of the page;
import random

This will make the computer import the tools for the node 'random'

Variables

variables.png
Next we need to get the user's numbers, and operation. To do that we'll use raw input. However, raw_input makes whatever the user inputs a string. We don't want that. So make that string an integer by using int(). We'll do this twice, to find the two numbers the user has in mind. Here is the user number variables;

num1 = int(raw_input('What is the first number'))
num2 = int(raw_input('What is the first number'))

Now we need to figure out what operation the user is doing. Use raw_input to ask.

op = raw_input('Are you adding, subtracting, multiplying or dividing? (input as + , - , * , /)')

Now the fun part, the random number. To do that, we need to make a variable to generate a random number, as an integer. Here is how;

rand = int(random.randint(2 , 9))

Wrapping It Up

if.png
Now all you need to do is make an if/elif/else statement to carry out the operation.

if op == '+':
print num1 + rand
elif op == '-':
print num1 - rand
elif op == '*':
print num1 * rand
elif op == '/':
print num1 / rand
else:
print 'I didn\'t understand you'

That's All

finis.png
That's all that you need to do! Go mess with friends, enemies, small children, etc, etc.
Have fun