Python Forum
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"if" beginner question
#3
Try this:

print("Please choose the combination you like:")
print("milk", "", "sugar", "", "tea", "", "coffee")
print("Choose the first one:")
first = input()
print("Choose the second one:")
second = input()
if first.upper()[0] == 'M' and second.upper()[0] == 'S':
 print("????????????")
elif first.upper()[0] == 'M' and second.upper()[0] == 'T':
  print("typical")
elif first.upper()[0] == 'S' and second.upper()[0] == 'T':
 print("okay")
elif first.upper()[0] == 'S' and second.upper()[0] == 'C':
 print("wake up")
else:
 print("Is there any other combination?")
I used a command .upper which converts the input to all caps. Then I used [0] which means that the input is now only the first letter and it's a capital letter. So if the user said coffee, python would read that as C. You could also use the 'or' command if you want.

elif first.upper()[0] == 'S' or 'T' and second.upper()[0] == 'T' or 'S':
 print("okay")
Like that. I hope this helps you, I know it helped me explaining this. I'm not that great of a programmer either but I'm learning! Wink
Reply


Messages In This Thread
"if" beginner question - by Naito - Jan-12-2019, 06:58 AM
RE: "if" beginner question - by Mr_W - Jan-12-2019, 01:07 PM
RE: "if" beginner question - by Trinx - Jan-12-2019, 05:08 PM
RE: "if" beginner question - by buran - Jan-12-2019, 05:10 PM
RE: "if" beginner question - by Trinx - Jan-12-2019, 05:13 PM
RE: "if" beginner question - by Trinx - Jan-12-2019, 10:43 PM
RE: "if" beginner question - by Naito - Jan-13-2019, 09:22 AM
RE: "if" beginner question - by perfringo - Jan-13-2019, 11:04 AM
RE: "if" beginner question - by Naito - Jan-13-2019, 12:51 PM
RE: "if" beginner question - by buran - Jan-13-2019, 12:57 PM
RE: "if" beginner question - by Mr_W - Jan-13-2019, 01:01 PM
RE: "if" beginner question - by Naito - Jan-13-2019, 01:12 PM
RE: "if" beginner question - by metulburr - Jan-13-2019, 01:31 PM
RE: "if" beginner question - by perfringo - Jan-13-2019, 02:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 317 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  A simple "If...Else" question from a beginner Serena2022 6 1,831 Jul-11-2022, 05:59 AM
Last Post: Serena2022
Question Beginner Boolean question [Guessing game] TKB 4 2,455 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Beginner question NameError amazing_python 6 2,624 Aug-13-2021, 07:28 AM
Last Post: amazing_python
  Beginner question - storing values cybertron2 4 3,330 Mar-09-2021, 04:21 AM
Last Post: deanhystad
  beginner question about lists and functions sudonym3 5 2,873 Oct-17-2020, 12:31 AM
Last Post: perfringo
  beginner question ___ 1 1,789 Jul-12-2020, 08:12 AM
Last Post: Gribouillis
  Beginner question: lxml's findall in an xml namespace aecklers 0 2,976 Jan-22-2020, 10:53 AM
Last Post: aecklers
  Super easy beginner question AkulaLA 3 3,385 Nov-07-2019, 03:42 AM
Last Post: Larz60+
  Basic Beginner question NHeav 4 2,893 Sep-13-2019, 11:43 AM
Last Post: NHeav

Forum Jump:

User Panel Messages

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