Jump to content

Hey guys, I'm wanting it to print this 

 

What is your favourite sport? tennis
That is my favourite sport too!
We should go play some tennis!
 
then if they answer something else I want it to print this
 
What is your favourite sport? soccer
We should go play some soccer!
 
this is what I have so far 
 
name = input('What is your favourite sport? ')
if name == 'tennis':   
  print('That is my favourite sport too!')
  print('We should go play some '+name+'!')
 
if name == 'soccer' or 'cricket':  
  print('We should go play some '+name+'!')   
 
but if they say tennis it prints the bottom line twice why is this?
 
What is your favourite sport? tennis
That is my favourite sport too!
We should go play some tennis!
We should go play some tennis!
 

 

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

Link to post
Share on other sites

Use elseif for the latter part.

name = input('What is your favourite sport? ')if name == 'tennis':     print('That is my favourite sport too!')  print('We should go play some '+name+'!')elseif name == 'soccer' or 'cricket':    print('We should go play some '+name+'!') 
Link to comment
https://linustechtips.com/topic/431101-learner-help/#findComment-5780473
Share on other sites

Link to post
Share on other sites

Use elseif for the latter part.

^exactly what I was going to suggest.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
https://linustechtips.com/topic/431101-learner-help/#findComment-5780479
Share on other sites

Link to post
Share on other sites

if name == 'soccer' or 'cricket': 

Isn't doing what you think it is. To check if name is either soccer or cricket you have to do 

if name == 'soccer' or name == 'cricket'

or

if name in ('soccer', 'cricket')

 

The way you have it will always return true because 'cricket' evaluates to True and True or anything is True.

1474412270.2748842

Link to comment
https://linustechtips.com/topic/431101-learner-help/#findComment-5780522
Share on other sites

Link to post
Share on other sites

 

Use elseif for the latter part.

name = input('What is your favourite sport? ')if name == 'tennis':     print('That is my favourite sport too!')  print('We should go play some '+name+'!')elseif name == 'soccer' or 'cricket':    print('We should go play some '+name+'!') 

It's elif, not elseif

Project Pluto
i3 4170 MSI H97 PC Mate MSI R9 380 2GD5T @ 1095MHz Kingston HyperX Fury Blue 2x4gb @ 1600MhzWD 1TB Blue • be quiet! Pure Rock • NZXT S340 Black XFX TS 550w • BenQ GW2265HM

 

Link to comment
https://linustechtips.com/topic/431101-learner-help/#findComment-5780526
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

×