0% found this document useful (0 votes)
72 views

Flow of Control - Type C Answers

The document contains 18 coding questions and their solutions in Python. The questions cover a range of programming concepts like conditional statements, loops, functions, lists, finding factors of numbers. Some questions ask the user to input values and perform calculations to check conditions or get outputs. Overall the questions aim to help students learn and practice basic Python programming skills.

Uploaded by

btskimnamjoon216
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Flow of Control - Type C Answers

The document contains 18 coding questions and their solutions in Python. The questions cover a range of programming concepts like conditional statements, loops, functions, lists, finding factors of numbers. Some questions ask the user to input values and perform calculations to check conditions or get outputs. Overall the questions aim to help students learn and practice basic Python programming skills.

Uploaded by

btskimnamjoon216
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

EMIRATES FUTURE INTERNATIONAL ACADEMY

INFORMATICS PRACTICES : GRADE 11

CHAPTER 5 : FLOW OF CONTROL (TYPE C)

1. Write a python script that ask the user to enter a length in centimeters. If the user enters a
negative length, the program should tell the user that the entry is invalid. otherwise, The
program should convert the length to inches and print out the result. there are 2.54
centimeters in an inch.
Code:
n = int(input("Enter the length in centimeter = "))
if n < 0 :
print("Invalid")
else :
length=n/2.54
print("Length in inch = ", length)

2. A store charges RS 120 per item if you buy less than 10 items. If you buy between 10 and
99 items ,the cost is RS100 per item . if you buy more items, The cost is RS 70 the user how
many items they are buying and print the total cost.
Code:
item = int(input("Enter the total number of items = "))

if item < 10 :
tot_cost=item * 120
print("Total cost = ",tot_cost , "rs")
elif 10 <= item and item <= 99 :
tot_cost=item * 100
print("Total cost = ",tot_cost, "rs")
else :
tot_cost=item * 70
print("Total cost = ",tot_cost , "rs")

3. Write a program to input length of three side of a triangle. then check if these side will
form a triangle or not.
Code:
a = int (input ("Enter the first side of triangle = "))
b = int (input ("Enter the second side of triangle = "))
c = int (input ("Enter the third side of triangle = "))
if a < b + c and b < a + c and c < a + b :
print ("It form the triangle")
else :
print ("It can not form triangle")

4. Write a program that reads from user -


(i) An hour between 1 to 12 and
(ii) Number of hours ahead. The program should then print the time after those many hours.
Code:
hour = int(input("Enter An hour between 1 to 12 :-"))
num = int(input("Enter Number of hours ahead :-"))
sum = hour + num
if sum <= 12 :
print("Time is ",sum,"o clock")
else :
print("Time is ",sum - 12,"o clock")

5. Write a program to take two numbers and print if the first number is fully divisible by
second number or not.
Code:
m = int(input("Enter the number = "))
n = int(input("Enter the divisor = "))
if m%n == 0:
print("It is divisible ")
else:
print("It is not divisible")
6. Write a short program to input a digit(1 -10) and print it in words.
Code:
day_no = int (input ("Enter the digit (1-10) ="))
if day_no ==1 :
print ("one ")
elif day_no ==2 :
print ("two")
elif day_no ==3 :
print ("three")
elif day_no == 4:
print ("four ")
elif day_no == 5:
print ("five")
elif day_no == 6:
print ("six ")
elif day_no == 7:
print ("seven")
elif day_no == 8:
print ("eight ")
elif day_no == 9:
print ("nine")
elif day_no == 10 :
print ("ten")
else:
print ("digit is out of range ")
7. Write a short program to print first n odd number in descending.
Code:
n = int(input("Enter value of n = "))
for i in range( (n * 2 - 1), 0 , -2) :
print(i, end = " , ")
8. Write a short program to print the following series:
(i) 1 4 7 10 ………. 40
(ii) 1 -4 7 -10 ………….. -40
Code:
(i)
for i in range(1,41,3):
print(i,end=" , ")
(ii)
for i in range(1,41,3):
if i % 2 == 0 :
print(-i,end=" , ")
else :
print(i,end=" , ")
9. Write a short program to find average of list of number entered through keyboard.
Code:
sum = 0
feq = 0
while True:
a = input("Enter a number (for quit enter Yes )= ")
if a == "Yes" or a == "yes" :
print("average of numbers = ",sum/feq)
break
else:
sum = sum + int(a)
feq = feq + 1
10. Write a short program to find largest number of the list of number entered through
keyboard.
Code:
b=0
while True :
a = int(input("Enter a number (for quit enter 0 (zero) )= "))
if a == 0 or a == 0 :
break
else :
if a > b :
b=a
print(b, "is biggest number.")
11. Write a program to input assets, liabilities and capital of a company and test if accounting
equation holds true for the given value (i.e., balanced or not).
Code:
assets = float(input("Enter assets :-"))
liabilities = float(input("Enter liabilities :-"))
capital = float(input("Enter capital :-"))

if assets == liabilities + capital :


print("Balanced")
else :
print("Not balanced")
12. Write a program to input total debt and total assets and calculate total-debt-to-total-assets
ratio (TD/TA) as Total Debt/Total Assets. Then print if the major portion of the debt is funded
by assets (when TD/TA > 1) or greater portion of assets is funded by equity (when TD/TA < 1).
Code:
total_debt = float(input("Enter total debt :-"))
total_assets = float(input("Enter total assets :-"))
ratio = total_debt / total_assets
if ratio > 1 :
print("the major portion of the debt is funded by assets ")
else :
print("greater portion of assets is funded by equity ")
13. Write a program to calculate Debt-to-equity (D/E) ratio as Total Liabilities after / Total
shareholders' equity after inputting total liabilities and total shareholders' equity. And then
print if an investor should invest in the company or not.
A D/E ratio greater than 2.0 indicates a risky scenario for an investor.
Code:
total_Liabilities = float(input("Enter Total Liabilities :-"))
Total_equity = float(input("Enter Total shareholders' equity :-"))
ratio = total_Liabilities / Total_equity
if ratio > 2 :
print("a risky scenario for an investor")
else :
print("investor should invest in the company ")
14. Write a program to input N number and then print the second largest number.
Code:
largest = 0
second = 0
while True :
a = int(input("enter a number (for quit enter 0 (zero) )= "))
if a == 0 or a== 0 :
break
else :
if a > largest :
second = largest
largest = a
print(second,"is second biggest number ")
15. Write a program that inputs cost price and selling price for 10 items. The prints if the
overall profit occurred or loss occurred.
Code:
total_cost = 0
total_sell = 0
for i in range(10):
cost = float(input("Enter cost price :-"))
sell = float(input("Enter selling price :-"))
total_cost += cost
total_sell += sell
if total_cost > total_sell :
print("Loss occurred")
else :
print("profit occurred")
16. Modify previous question so that the program now also prints profit/loss for individual
items along with overall profit/loss.
Code:
total_cost = 0
total_sell = 0
for i in range(10):
print( i+1 ,"item")
cost = float(input("Enter cost price :-"))
sell = float(input("Enter selling price :-"))
if cost > sell :
print("Loss")
else :
print("Profit")
total_cost += cost
total_sell += sell
if total_cost > total_sell :
print("Loss occurred")
else :
print("profit occurred")
17. Write a python program to print every integer between 1 and n divisible by m. also report
whether the number that is divisible by m is even or odd.
Code:
n = int(input("Enter n = "))
m = int(input("Enter m as divisor = "))
for i in range(1,n):
if i % m == 0 :
if i % 2 == 0 :
print(i,"is divisible by m and this is even number ")
else :
print(i,"is divisible by m and this is odd number ")
18. Write a program to display all of the integers from 1 up to and including some integer
entered by the user followed by a list of each number's prime factors. Numbers greater than 1
that only have a single prime factor will be marked as prime.
For example, if the user enters 10 then the output of the program should be:
Enter the maximum value to display: 10
1=1
2 = 2 (prime)
3 = 3 (prime)
4 = 2x2
5 = 5 (prime)
6 = 2x3
7 = 7 (prime)
8 = 2x2x2
9 = 3x3
10 = 2x5
Code:
num = int(input("Enter a number :-"))
print("1 = 1 \n2 = 2(prime)")
for i in range(3,num+1):
print(i ,end=" = ")
prime = 0
multiply = 1
factor = ""
number = i
for j in range(2,i):
while number % j == 0:
prime = 1
multiply *= j
if multiply > i :
break
else :
factor+= str(j)+"x"
number = number // j
if multiply > i :
break
print(factor[:-1],end="")
if prime == 0:
print(i,"(prime)",end="")
print()

You might also like