Python Forum
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"if" beginner question
#11
I think because a can't be (for example) 'milk' and 'MILK' so to fix that problem you can write:
x="milk"
y="sugar"
z="tea"
t="coffee"
but ofcours the user can write it as Coffee or COFFEE so we have to rule out any upper case characters. You can modify a string by using .lower() or .upper() to change the whole string to upper or lower case. So to change the input to all lower case it would be a = input().lower().
For more explanation:
https://www.tutorialspoint.com/python/string_lower.htm

The full working code is in the spoiler but try it yourself first :)
Reply
#12
(Jan-13-2019, 01:01 PM)Mr_W Wrote: I think because a can't be (for example) 'milk' and 'MILK' so to fix that problem you can write:
x="milk"
y="sugar"
z="tea"
t="coffee"
but ofcours the user can write it as Coffee or COFFEE so we have to rule out any upper case characters. You can modify a string by using .lower() or .upper() to change the whole string to upper or lower case. So to change the input to all lower case it would be a = input().lower().
For more explanation:
https://www.tutorialspoint.com/python/string_lower.htm

The full working code is in the spoiler but try it yourself first :)
thank you Mr_W that's so useful Big Grin
thank you buran
Reply
#13
also its common practice to use 4 spaces for indentation, not one. It much easier to identify.
Its a PEP 8 guideline.
Recommended Tutorials:
Reply
#14
If names x, y, z, t are not used anywhere else it can be expressed in more readable form:

>>> first = input("Choose the first one: ").lower()
>>> second = input("Choose the second one: ").lower()
>>> if first == 'milk' and second == 'tea':
...     print("????????????")
... elif first == 'milk' and second == 'coffee':
...     print("typical")
... elif first == 'sugar' and b == 'tea':
...     print("okay")
... elif first == 'sugar' and second == 'coffee':
...     print("wake up")
... else:
...     print("is there any other comb?")
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A simple "If...Else" question from a beginner Serena2022 6 1,638 Jul-11-2022, 05:59 AM
Last Post: Serena2022
Question Beginner Boolean question [Guessing game] TKB 4 2,227 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Beginner question NameError amazing_python 6 2,379 Aug-13-2021, 07:28 AM
Last Post: amazing_python
  Beginner question - storing values cybertron2 4 3,137 Mar-09-2021, 04:21 AM
Last Post: deanhystad
  beginner question about lists and functions sudonym3 5 2,666 Oct-17-2020, 12:31 AM
Last Post: perfringo
  beginner question ___ 1 1,704 Jul-12-2020, 08:12 AM
Last Post: Gribouillis
  Beginner question: lxml's findall in an xml namespace aecklers 0 2,864 Jan-22-2020, 10:53 AM
Last Post: aecklers
  Super easy beginner question AkulaLA 3 3,173 Nov-07-2019, 03:42 AM
Last Post: Larz60+
  Basic Beginner question NHeav 4 2,708 Sep-13-2019, 11:43 AM
Last Post: NHeav
  Beginner Question - Esaping the Escape Character correctly? Bramen 4 2,653 Aug-27-2019, 02:38 PM
Last Post: Bramen

Forum Jump:

User Panel Messages

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