0% found this document useful (0 votes)
3 views3 pages

Question

The document contains a series of Python code snippets that demonstrate various programming concepts such as conditional statements, loops, and input handling. Each question addresses a different problem, including temperature classification, grade determination based on marks, leap year checking, age categorization, triangle validity, finding the largest number, calculating absolute difference, generating Fibonacci sequences, creating multiplication tables, and counting character occurrences in a string. The code is structured to take user input and provide appropriate outputs based on the logic implemented.

Uploaded by

umair33862
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Question

The document contains a series of Python code snippets that demonstrate various programming concepts such as conditional statements, loops, and input handling. Each question addresses a different problem, including temperature classification, grade determination based on marks, leap year checking, age categorization, triangle validity, finding the largest number, calculating absolute difference, generating Fibonacci sequences, creating multiplication tables, and counting character occurrences in a string. The code is structured to take user input and provide appropriate outputs based on the logic implemented.

Uploaded by

umair33862
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# Question # 1

temperature = int(input("Enter a temperature: "))


if temperature <= 18:
print("It's Cold")
elif temperature > 18 and temperature < 24:
print("It's Warm")
else:
print("It's Hot")

# Question # 2

Marks = int(input("Enter a Marks: "))


if Marks >= 80:
print("A+ Grade")
elif Marks >=70 and Marks < 80:
print("A Grade")
elif Marks >=60 and Marks < 70:
print("B Grade")
elif Marks >=50 and Marks < 60:
print("C Grade")
elif Marks >=40 and Marks < 50:
print("D Grade")
else:
print("Fail")

# Question # 3

year = int(input("Enter a year: "))


if year % 4 == 0:
if year % 100 !=0 or year % 400 == 0:
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")
else:
print(f"{year} is not a leap year")

# Question # 4

age = int(input("Enter a age: "))


if age < 0 or age > 120 :
print("Invalid age")
elif age < 13:
print("Child")
elif age < 20:
print("Teenager")
elif age < 60:
print("Adult")
else:
print("Senior citizen")

# Question # 5

angle1 = int(input("Enter a angle1: "))


angle2 = int(input("Enter a angle2: "))
angle3 = int(input("Enter a angle3: "))
if angle1 > 0 and angle2 > 0 and angle3 > 0 and (angle1 + angle2 + angle3 ==180):
print("Valid triangle")
else:
print("not a valid triangle")

# Question # 6

num1 = int(input("Enter a num1: "))


num2 = int(input("Enter a num2: "))
num3 = int(input("Enter a num3: "))
if num1 > num2 and num1 > num3:
largest = num1
elif num2 > num1 and num2 > num3:
largest = num2
else:
largest = num3
print("The largest number is",largest)

# Question # 7

a = int(input("Enter a First number: "))


b = int(input("Enter a Seconnd number: "))
# Conditional expression to find out absolute difference
difference = a-b if a > b else b-a
print("The absolute difference is ",difference)

# Question # 8

n = int(input("Enter a number of terms: "))


a , b = 0 , 1
count = 0
if n <= 0:
print("please enter positive integers.")
elif n ==1:
print("Fibonacci Sequence up to 1 terms")
print(a)
else:
print("Fibonacci Sequence:")
while count < n:
print(a, end=' ')
a , b = b , a + b
count = count + 1

# Question # 9

number = int(input("Enter a number: "))


print(f"Multiplication table for a {number}:")
for i in range (1 , 11):
print(f"{number} X {i} = {number * i}")

# Question # 10

text = input("Enter a string: ")


char_to_count = input("Enter a character to count: ")
count = 0
for char in text:
if char == char_to_count:
count = count + 1
print(f"The character '{char_to_count}' appears {count} times in a string")

You might also like