Bottom Page

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 :)
Quote
#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
Quote
#13
also its common practice to use 4 spaces for indentation, not one. It much easier to identify.
Its a PEP 8 guideline.
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  question by a beginner salahoum 6 157 Jan-16-2019, 10:40 AM
Last Post: salahoum
  beginner question Naito 2 93 Jan-15-2019, 07:59 AM
Last Post: Naito
  Absolute Beginner Python Question matchamochi7 5 289 Nov-02-2018, 12:09 PM
Last Post: wookie
  Very beginner but please help! thurpe 2 271 Jul-31-2018, 04:04 PM
Last Post: thurpe
  Beginner Loop question BigDisAok 5 470 Jul-24-2018, 02:04 PM
Last Post: BigDisAok
  beginner Kyrophis 1 325 Jun-26-2018, 05:25 PM
Last Post: Larz60+
  Very beginner needs help bostltch 3 559 Feb-04-2018, 12:17 AM
Last Post: Larz60+
  Beginner question: help ensuring input is a number ycrad 2 562 Dec-23-2017, 10:49 PM
Last Post: snippsat
  Beginner question HimynameisBen 4 825 Nov-03-2017, 07:58 PM
Last Post: nilamo
  Beginner willianramos 4 824 Oct-13-2017, 07:36 PM
Last Post: willianramos

Forum Jump:


Users browsing this thread: 1 Guest(s)