Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chauhan-tarun/16bd19ffaf898a9df0d13ec0bb6f825e to your computer and use it in GitHub Desktop.
Save chauhan-tarun/16bd19ffaf898a9df0d13ec0bb6f825e to your computer and use it in GitHub Desktop.
Exercise answers of video tutorial "Python 3 for beginners - #5.Conditions" by TheTechnicalFist : https://youtu.be/HhcnV7rB86E
# 1. Take input from user, test whether it is even or odd
# Take input
number = eval(input("Enter a number : "))
# Check if number is even or odd
if number % 2 == 0:
print("It is an even number")
else:
print("It is an odd number")
# #####################################################################################
# 2. Take values of length/width and breadth/height of a rectangle from user and check if it is square or not.
# Take Width and Height from user
width = eval(input("Enter width : "))
height = eval(input("Enter height : "))
# Check if it is square or not
if width == height:
print("It is a square")
else:
print("It is not a square")
# #####################################################################################
# 3. Take input of age of 3 people by user and determine oldest and youngest among them
# Take Ages
person1 = eval(input("Enter age of person 1 : "))
person2 = eval(input("Enter age of person 2 : "))
person3 = eval(input("Enter age of person 3 : "))
# check oldest
if person1 > person2 and person1 > person3:
print("Person 1 is oldest")
elif person2 > person1 and person2 > person3:
print("Person 2 is oldest")
elif person3 > person1 and person3 > person2:
print("Person 3 is oldest")
# check youngest
if person1 < person2 and person1 < person3:
print("Person 1 is youngest")
elif person2 < person1 and person2 < person3:
print("Person 2 is youngest")
elif person3 < person1 and person3 < person2:
print("Person 3 is youngest")
# #####################################################################################
# 4. A student will not be allowed to sit in exam if his/her attendance is less than 75%
# Get total classes held in school
totalClassesHeld = eval(input("Enter total number of classes held in school : "))
# Get total classes attended by the student
totalClassesAttend = eval(input("Enter total number of classes attended by the student : "))
# Get percent of the attendance
percent = (totalClassesAttend / totalClassesHeld) * 100
# Check if percent is above 75 i.e., eligible to sit in exam or not
if percent < 75:
print("You cannot sit in the exams as your attendance is too low!")
else:
print("You can sit in the exams as your attendance is fine.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment