Jump to content

I have recently started programming in python and I decided to tackle a small project, there won't be any graphics or pictures just a questionnaire that guesses your age.

 

This question is kind of a tough question to put into words so bear with me   :P.

 

Essentially I need to know how to make it to where if a person replies "yes" to a certain question then a certain number is put into a mathematical equation and a different number that goes into that equation if they were to reply "no".

 

For Example: say, Yes = 1  and No = 2

 

If they typed Yes than they would get the answer "2" (1+1)

If they typed No then they would get the answer "3" (2+1)

 

 

If that was a little tough to understand I apologize and please don't hate, I've only just started in Python.

 

Thank You!

Link to comment
https://linustechtips.com/topic/310475-python-help/
Share on other sites

Link to post
Share on other sites

x=raw_input()int numberint answerif x=="yes":    number=5elif x=="no":    number=6answer=number+10print answer

I havent done python in a year so there may be some tiny bugs...

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/310475-python-help/#findComment-4220057
Share on other sites

Link to post
Share on other sites

x=raw_input()int numberint answerif x=="yes":    number=5elif x=="no":    number=6answer=number+10print answer

I havent done python in a year so there may be some tiny bugs...

 

Thanks I'll try it out and let you know if it worked, and I had one more question. Do the order of operations apply in Python?

Link to comment
https://linustechtips.com/topic/310475-python-help/#findComment-4220100
Share on other sites

Link to post
Share on other sites

Thanks I'll try it out and let you know if it worked, and I had one more question. Do the order of operations apply in Python?

You're welcome, let me know how it goes.

Yes python knows BEDMAS, but you can always use brackets () to make sure everything is done in the order you want

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/310475-python-help/#findComment-4220145
Share on other sites

Link to post
Share on other sites

You're welcome, let me know how it goes.

Yes python knows BEDMAS, but you can always use brackets () to make sure everything is done in the order you want

Thanks and how do I make the things that are printed show up one at a time (it only works on the first one for some reason)?

Link to comment
https://linustechtips.com/topic/310475-python-help/#findComment-4220171
Share on other sites

Link to post
Share on other sites

Thanks and how do I make the things that are printed show up one at a time (it only works on the first one for some reason)?

You mean like on a new line each time?

do

print "\n"

for a new line :)

 

you can also do

print "hello there\nthis is now a new line"

and the stuff after \n will be on a new line

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/310475-python-help/#findComment-4220184
Share on other sites

Link to post
Share on other sites

You mean like on a new line each time?

do

print "\n"

for a new line :)

 

you can also do

print "hello there\nthis is now a new line"

and the stuff after \n will be on a new line

Lol I figured it out  and no, I was talking about when a question is asked you answer it then a second question is asked and so on. But I already figured it out (it was a comma)

Link to comment
https://linustechtips.com/topic/310475-python-help/#findComment-4220221
Share on other sites

Link to post
Share on other sites

It is say that int number is an invalid syntax.

k then do

number=0

or try just

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/310475-python-help/#findComment-4220261
Share on other sites

Link to post
Share on other sites

 

 

x=raw_input()

int number <--------- not needed 

int answer <--------- not needed 

if x=="yes":

    number=5

elif x=="no":

    number=6

answer=number+10

print answer

 

hey guys, In python you do not have to initialize a variable before it's use or define it's type. All of this is done at the time of first assignment, also everything is an object with a type so can just change at any point.

 

like this.

number = 0number = "string" 

So when I do the first line the variable number is an object with the assignment of 0 and it's type is int. then when I reassign this, the value and the type of the variable change to "string" and string respectively but it is still an object.

 

this theory goes right the way through python, from classes, to functions, to variables, everything is a object with a type. 

Link to comment
https://linustechtips.com/topic/310475-python-help/#findComment-4223168
Share on other sites

Link to post
Share on other sites

It is say that int number is an invalid syntax.

k then do

number=0

or try just

Like said in the above post, you don't need to define a variable before you assign it a value in Python. Just leave that code out, as it has no real purpose and is just extra unneccessary code in your program.

CPU: AMD FX-6300 4GHz @ 1.3 volts | CPU Cooler: Cooler Master Hyper 212 EVO | RAM: 8GB DDR3

Motherboard: Gigabyte 970A-DS3P | GPU: EVGA GTX 960 SSC | SSD: 250GB Samsung 850 EVO

HDD: 1TB WD Caviar Green | Case: Fractal Design Core 2500 | OS: Windows 10 Home

Link to comment
https://linustechtips.com/topic/310475-python-help/#findComment-4228299
Share on other sites

Link to post
Share on other sites

Like said in the above post, you don't need to define a variable before you assign it a value in Python. Just leave that code out, as it has no real purpose and is just extra unneccessary code in your program.

sorry ive been doing c++ for a year and i kinda forgot python :P

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/310475-python-help/#findComment-4228310
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

×