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')

11th Aug 2023, 6:39 AM
Olayinka Daniel Aborisade
Olayinka Daniel Aborisade - avatar
10 Answers
0
Btw, I see bool function with a string always returns True, that's why I modified it a bit.
11th Aug 2023, 10:24 AM
Dragon RB
Dragon RB - avatar
+ 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
11th Aug 2023, 6:45 AM
Lisa
Lisa - avatar
+ 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`.
11th Aug 2023, 11:15 AM
Lothar
Lothar - avatar
+ 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.
11th Aug 2023, 8:40 PM
Lothar
Lothar - avatar
+ 2
Olayinka Daniel Aborisade , https://code.sololearn.com/c80m2eo9342D/?ref=app Please read the code carefully to fully understand it.
11th Aug 2023, 7:07 AM
Dragon RB
Dragon RB - avatar
+ 1
Thanks for the tip Lisa
11th Aug 2023, 6:55 AM
Olayinka Daniel Aborisade
Olayinka Daniel Aborisade - avatar
+ 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
11th Aug 2023, 1:26 PM
Olayinka Daniel Aborisade
Olayinka Daniel Aborisade - avatar
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
11th Aug 2023, 6:59 AM
Olayinka Daniel Aborisade
Olayinka Daniel Aborisade - avatar
0
Thanks Dragon RB, I'll review and revert asap
11th Aug 2023, 10:21 AM
Olayinka Daniel Aborisade
Olayinka Daniel Aborisade - avatar
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
11th Aug 2023, 12:44 PM
Olayinka Daniel Aborisade
Olayinka Daniel Aborisade - avatar