Posts

Showing posts with the label print

Calculate user age and when will they turn 100

The following Python program calculates 2 things; 1. when will the user turn 100 2. what will be the user's age in a certain year  # when will I be 100 years old age_yob = input("Plz enter your age or year of birth: ") # my age in the future year age_in_year = input("You age in a certain year: ") current_year = 2022 # age_in_year = float(age_in_year) # dealing age try: if len(age_yob) < 4: if len(age_yob) == 3: print("You are already 100 years old.") elif len(age_yob) < 3: age_100 = 100 - float(age_yob) print(f"You will turn 100 in {current_year + age_100}") add_to_age = float(age_in_year) - current_year age_asked = float(age_yob) + add_to_age print(f"You age in {age_in_year} will be {age_asked}") else: # dealing yob age_100 = float(age_yob) + 100 print(f"You will turn 100

The First Ever Python Program - Learning print() function

Image
Hi Everyone! This is the first-ever Python program that I learned in my life and the same is true I bet pretty much about every absolute beginner like me. Anybody who newly steps into programming will encounter this program learning.  This is indeed a baby program but it matters much as far as the absolute newbie is concerned.  This program is learning to use the print function, i.e.  print() Let's learn how to use this function! This is actually a built-in function in Python and is used to print anything that we want to display to the user.  It is very simple to use. Just type in the round parenthesis of print function your desired text that you want to be shown at the terminal or displayed to the end-user. And don't forget to quote-unquote your text.  Let's understand this with an example; Let's say I want to print 'Good morning' to the user. All I have to do is the following; print("Good morning") . . .and the user should see the message   'Good