Python Forum
Using answers from an input function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using answers from an input function
#1
I've decided to teach myself programming and am new to the science. I started with a book on python and often try write code that's more complex than the examples provided in the book.

To get to the point here is an example from the book about the if and elif statements.
print("1. Red")
print("2. Orange")
print("3. Yellow")
print("4. Green")
print("5. Blue")
print("6. Purple")
Choice = int(input("Select your favorite color: "))
if (Choice == 1):
    print("You chose Red!")
elif (Choice == 2):
    print("You chose Orange!")
elif (Choice == 3):
    print("You chose Yellow!")
elif (Choice == 4):
    print("You chose Green!")
elif (Choice == 5):
    print("You chose Blue!")
elif (Choice == 6):
    print("You chose Purple!")
else:
    print("You made an invalid choice!")
Reply


Messages In This Thread
Using answers from an input function - by Totalartist - Jul-19-2019, 01:28 PM
RE: Using answers from an input function - by Yoriz - Jul-19-2019, 01:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,220 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  'answers 2' is not defined on line 27 0814uu 4 835 Sep-02-2023, 11:02 PM
Last Post: 0814uu
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,208 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Showing an empty chart, then input data via function kgall89 0 1,030 Jun-02-2022, 01:53 AM
Last Post: kgall89
  input function question barryjo 12 2,946 Jan-18-2022, 12:11 AM
Last Post: barryjo
  function with 'self' input parameter errors out with and without 'self' called dford 12 3,324 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  Problem with input after function luilong 10 4,274 Dec-04-2021, 12:16 AM
Last Post: luilong
  Exit function from nested function based on user input Turtle 5 3,067 Oct-10-2021, 12:55 AM
Last Post: Turtle
Star I'm getting syntax error while using input function in def. yecktmpmbyrv 1 2,047 Oct-06-2021, 09:39 AM
Last Post: menator01
  Division calcuation with answers to 1decimal place. sik 3 2,221 Jul-15-2021, 08:15 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020