Python: Input Review

Post Reply
User avatar
Jason
Site Admin
Posts: 853
Joined: Tue Jul 01, 2025 10:13 am

Code: Select all

# The following line assumes the variable is a string.

school_name = input("If you went to college or university, where did you go?")

# The input function only takes str, which means string, so conversion is needed for all else.


# Now, let's look at floats.

GPA = float(input(If you went to college or university, what was your GPA?))


# Now, let's look at int which are integers.

age_when_starting_uni_or_college = int(input("If you went to college or university, then what age did you begin?"))


# Now, let's look at bool which are booleans.

while True:

	is_Duke_in_North_Carolina = bool(input("Is Duke in North Carolina, True or False 		   (case sensitive)?"))

	If is_Duke_in_North_Carolina == 'True':
		
		print("You are right. Duke is in North Carolina.")
		
	else:

		print("You are wrong. Duke is in North Carolina.")
	

Code: Select all

print(f"You went to {school_name}. Your GPA was {GPA}. You started school at age {age_when_starting_uni_or_college}.")
 

POSTREACT(ions) SUMMARY

Post Reply