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

Source Codes: Question No.1

The document contains 17 coding questions related to Python programming. The questions cover a range of topics including calculating averages and grades from marks, calculating discounts, area and perimeter of shapes, simple and compound interest, profit/loss calculations, EMI calculations, tax calculations, finding maximum/minimum values in lists, counting characters in strings, creating dictionaries of student data, and more. The questions demonstrate how to take user input, perform calculations, use conditional statements and loops, and print outputs.

Uploaded by

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

Source Codes: Question No.1

The document contains 17 coding questions related to Python programming. The questions cover a range of topics including calculating averages and grades from marks, calculating discounts, area and perimeter of shapes, simple and compound interest, profit/loss calculations, EMI calculations, tax calculations, finding maximum/minimum values in lists, counting characters in strings, creating dictionaries of student data, and more. The questions demonstrate how to take user input, perform calculations, use conditional statements and loops, and print outputs.

Uploaded by

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

Source Codes

18 August 2022 12:04

Question no.1:

math = float(input("Enter Maths marks:"))


english = float(input("Enter English marks:"))
science = float(input("Enter Science marks:"))
average = (math+english+science)/3
print(average)
if average<=50.0:
print("You have failed.")
elif average<=60.0:
print("Grade C")
elif average<=70.0:
print("Grade B")
elif average<=80.0:
print("Grade B*")
elif average<=90.0:
print("Grade A*")
elif average<=100:
print("Grade A*")

Question no.2:

cost = float(input("Enter cost(ignore symbol) of item:"))


discount = float(input("Enter discount:"))
print("Discount on product",discount,"%")
sales_price = cost*(discount/100)
print("Original price of product is",cost)
print("The price of product at discount is",sales_price)

Question no.3:

import math
def area_square(a):
area1=float(a*a);
print("Area of square is:",area1)
def area_circle(r):
area2=float(3.14*r*r);
print("Area of circle is:",area2)
def area_rectangle(a,b):
area3=float(a*b);
print("Area of rectangle is:",area3)
def area_triangle(x,y):
area4=float((x*y)/2);
print("Area of triangle is:",area4)
def peri_square(a):
peri1=float(4*a);
print("Perimeter of square is:",peri1)
def peri_circle(r):
peri2=float(2*3.14*r);
print("Perimter of circle is:",peri2)
def peri_triangle(a,b):
hypotenuse=float(math.sqrt(a*a+b*b))
peri3=float(a+b+hypotenuse)
print("Perimeter of right angled triangle is:",peri3)
def peri_rectangle(a,b):
peri4=float(2*(a+b))
print("Perimeter of rectangle is:",peri4)
side=float(input("enter the side of square:"))
area_square(side)
print()
peri_square(side)
radius=float(input("enter the radius of circle:"))
area_circle(radius)
peri_circle(radius)
length=float(input("enter the length of rectangle:"))
breadth=float(input("enter the breadth of rectangle:"))
area_rectangle(length,breadth)
peri_rectangle(length,breadth)
base=float(input("enter the base of right angled triangle:"))
height=float(input("enter the height of right angled triangle:"))
area_triangle(base,height)
peri_triangle(base,height)

Question no. 4:

principal = float(input('Enter amount: '))


time = float(input('Enter time: '))
rate = float(input('Enter rate: '))
simple_interest = (principal*time*rate)/100
compound_interest = principal * ( (1+rate/100)**time - 1)
print('Simple interest is: %f' % (simple_interest))
print('Compound interest is: %f' %(compound_interest))

Question no. 5:

CP = float(input(" Please Enter the Cost Price of the product: "))


SP = float(input(" Please Enter the Sale Price of the product: "))
if(CP > SP):
amount = CP - SP
print("Total Loss Amount = {0}".format(amount))
elif(SP > CP):
amount = SP - CP
print("Total Profit = {0}".format(amount))
else:
print("There is no Profit no Loss....")

Question no. 6:

def emi(p, r, t):


r = r/(12*100)
t = t*12
emi = (p*r*pow(1+r,t))/(pow(1+r,t)-1)
return emi
principal = float(input("Enter principle here: "))
rate = float(input("Enter rate of interest here:"))
time = float(input("Enter time here:"))
emi = emi(principal, rate, time);
print("Monthly EMI is= ", emi)

Question no. 7:
income = float(input("Enter your monthly income here: "))
GST = 18
print("GST is",GST,"%")
tax = income - (income*GST/100)
print("The tax levied on your income is:",tax)
new_income = income - tax
print("Your new income is:",new_income)

Question no. 8:

lst = []
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Maximum element in the list is :", max(lst), "\nMinimum element in the list
is :", min(lst))

Question no. 9:

lst = []
num = int(input('How many numbers:' ))
for n in range(num):
numbers = int(input("Enter number"))
lst.append(numbers)
lst.sort()
print("Second largest number in the list is:",sorted(lst)[-2])
print("Second smallest number in the list is:",sorted(lst)[-1])

Question no.10:

sum_of_squares = sum([num ** 2 for num in range(101)])


print(sum_of_squares)
Question 11:
num = int(input("Enter the number:")
N = int(input("Enter the number of multiples you want:"))

print("Multiples are:")
for a in range(1,n+1):
res = num*a
print(res)

Question 12:
String = input("Enter a string:")
Vowels = 0
For i in string:
if (i == 'a' or i == 'e' or i == 'i' or i=='u'):
vowels = vowels + 1
Print("Number of vowels in the string is:")
Print(vowels)

Question 13:
S = input("Enter any sentences:")
A = input("Enter any alphabet to find:")
Found = false
Words = s.split()
For word in words:
if word.startswith(a)
print(word)
found = true
if(found==false):
print("No word starting with user entered alphabet.")

Question 14:
Count = 0
My_string = input("Enter your word/sentence:")
My_char = input("Enter the alphabet:")
For i in my_string:
if i == my_char
count +=1

Print("The string entered:",my_string)


Print("The alphabet entered:",my_char)
Print("The number of occurences:"count)

Question 16:
Students = dict()
N = 5
For i in range(n):
sname = input("Enter names of students:")
marks = []
for j in range(5):
mark = float(input("Enter marks:")
marks.append(mark)
students[sname] = marks
Print("Dictionary of student created:")

Question 17:

My_dict = {'x':500,'y':5874,'z':560}

Key_max = max(my_dict.keys(),key = lambda k:my_dict[k])

Key_min = min(my_dict.keys(),key(lambda k:my_dict [])

You might also like