Jump to content

So im trying to learn Python and im using 2.7 becasue my Python videos use that and its working and so I am trying to write my second little program its a calculator which takes integer input from the user and chooses a function heres my shot at it and it works:

 

num1 = input("Enter first number")

input("Pick a function add,subtract,divide or multiply")

num2 = input("Enter second number")

 

so this ^ works it does what its supposed to takes the input but the function part isnt exactly there as I am struggling with that so I want to ask is there a way for example when the User inputs the function Add I want the code to recognise that the User has entered that function and carry it out as a normal calculator does, don't ask why I'm doing a calculator I just want to learn thanks guys

Link to comment
https://linustechtips.com/topic/205431-need-help-in-python-27/
Share on other sites

Link to post
Share on other sites

num1 = input("Enter first number") x=input("Pick a function add,subtract,divide or multiply") num2 = input("Enter second number") if x=="add":        answer = num1+num2 print answer 

k try this :)

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/205431-need-help-in-python-27/#findComment-2788862
Share on other sites

Link to post
Share on other sites

num1 = input("Enter first number") x=input("Pick a function add,subtract,divide or multiply") num2 = input("Enter second number") if x=="add":        answer = num1+num2 print answer 

k try this :)

 

that would work execpt its now saying Name Error 'answer' is not deffined

Link to comment
https://linustechtips.com/topic/205431-need-help-in-python-27/#findComment-2788954
Share on other sites

Link to post
Share on other sites

that would work execpt its now saying Name Error 'answer' is not deffined

oh do

answer=' '

at the start of the code

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/205431-need-help-in-python-27/#findComment-2789187
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

×