0
How do I create an input for is_student for entry by PROGRAM users
Hi all, please need to verify how to include an input statement for is_student instead of having to declare it. Because users may be less than the student age and still not to a student. How do I write a code with such syntax please? Somebody, onebody, help out please!!! age = int(input()) is_student = bool(input()) if age < 18: #execute if age is less than 18 & also a student elif is_student = true: print('20% discount') else: #execute if under 18 and not a student print('10% discount') else: print('no discount')
10 Réponses
0
Btw, I see bool function with a string always returns True, that's why I modified it a bit.
+ 3
DO NOT put code in the title section. IT GETS CUT OFF. Show your COMPLETE code.
Tag the RELEVANT PROGRAMMING LANGUAGE.
"=" is assignment
"==" is comparison for equality
+ 3
Olayinka Daniel Aborisade ,
to get an input as a boolean (True, False), you can use this line of code:
...
is_student = input().lower() in ['y', 'yes']
...
> if the input is `y` or `yes` (or in any combination with upper case letters), the result of the comparison is `True` and is stored in the variable `is_student`.
> for any other input, the result of the comparison is `False` and is stored in the variable `is_student`.
+ 3
Olayinka Daniel Aborisade ,
the mix of upper / lower case letters is meant for `input` like:
> `y`, `Y`, `Yes`, `YEs`, ... will work. this is possible because the input will be converted to all lower case, and after this the `in` operator is used with the list.
+ 2
Olayinka Daniel Aborisade ,
https://code.sololearn.com/c80m2eo9342D/?ref=app
Please read the code carefully to fully understand it.
+ 1
Thanks for the tip Lisa
+ 1
Never mind Lothar
I think I get what you're trying to say now.
Defining the code syntax to allow the character mix as I stated above.
Thanks
0
But what am trying to say is, assuming in real life on a campus setting. Someone wants to use one of the schools facility and has to input their status to know level of discount accessible.
So the program demands for age and student status (true or false) inputs.
How do you create the is_student input statement?
That's my question.
I tried using is_student = bool(input ())
But it didn't work
0
Thanks Dragon RB, I'll review and revert asap
0
Thanks Lothar.
When you ay any combination with upper case letters,
Does that mean upper and lower case inputs as shown below wil work;
True
TRUE
true
False
false
FALSE