I’m wanting to print "mins" if the user inputs a number with "m" after; and "hours" if user inputs number with "h" after.
import pyautogui xtime = (input("Enter time (add: m for mins, or h for hrs): ")) if xtime + "m": print("mins") elif xtime + "h": print("hours")
I don’t know how to do this, I’m just guessing, could someone please help me? Thanks.
The problem of your code is that what you’re doing is adding a "m" if the string
xtime is not null.
You should use
str.endswith Python built-in function:
xtime = (input("Enter time (add: m for mins, or h for hrs): ")) if xtime.endswith('m'): print("mins") elif xtime.endswith('h'): print("hours")