Uploaded by raza.arsalaan

Final Exam Aloksh

advertisement
#Final_Exam
#Name: #CS 114 section 001
#Date: *******************************************************************
***********************************Question:1**********************
#MathIsFun_Aloksh.txt
*****************************************************
**********************Portion:1**********************
*****************************************************
def totalN(n):
totalN = 0
for i in range(1,n+1):
totalN = totalN + i
return totalN
n = eval(input("how many numbers do you want: "))
print(totalN(n))
============= RESTART: D:\college\Final Exam\Program_1.1.py =============
how many numbers do you want: 3
6
>>> *****************************************************
*******************Protion:2*************************
*****************************************************
#convert_revised_2_Aloksh.txt
def totalMCube(m): totalMCube = 0
for i in range(1, m + 1): totalMCube += i * i*i return totalMCube
m = eval(input("enter the Number of digits form 0 to you want to add "))
print(totalMCube(m))
============= RESTART: D:\college\Final Exam\Program_1.2.py =============
enter the Number of digits form 0 to you want to add: 3
36
>>> *****************************************************
**********************Portion:3**********************
*****************************************************
def totalN(n):
totalN=0
for i in range(1,n+1):
totalN= totalN+i
return totalN
def totalMCube(m): totalM = 0
for i in range(1, m + 1): totalM += i * i*i return totalM
def main():
print("This Program Computes the total and total of cubes of first ")
print("N/M natural number .\n")
n,m=input("please enter the value of n and m ").split(",")
print(f"The total of the first,{n},Natural numbers is ,{totalN(int(n))}")
print(f"The total of the cubes of the first , {m} ,natural numbers is ,{totalMCube(int(m))}")
main()
============= RESTART: D:/college/Final Exam/Program_1.3.py =============
This Program Computes the total and total of cubes of first N/M natural number .
please enter the value of n and m 2,5
The total of the first,2,Natural numbers is ,3
The total of the cubes of the first , 5 ,natural numbers is ,225
>>> *******************************************************************
***********************************Question:2**********************
def main():
x = "celsius"
y = "fahrenheit"
print ("{0:>12} {1:>18}".format(x,y))
for celsius in range (-20, 110, 10):
fahrenheit = 9/5 * celsius + 32
print ("{0:>12} {1:>18}".format(celsius, fahrenheit))
main()
============= RESTART: D:/college/Final Exam/Program_2.1.py =============
celsius fahrenheit
-20 -4.0
-10 14.0
0 32.0
10 50.0
20 68.0
30 86.0
40 104.0
50 122.0
60 140.0
70 158.0
80 176.0
90 194.0
100 212.0
>>> *******************************************************************
***********************************Question:3**********************
*******************************************************************
#Algorithm_Aloksh.txt.
def main():
age = eval(input("Enter the age: "))
citizenship = eval(input("for How long you have being the citizen of USA? "))
if (age >= 30) and (citizenship >= 9):
print("The candidate is eligible to be a member of Senate.")
elif (age >= 25) and (citizenship >= 7):
print ("The candidate is eligible to be a member of the U.S. House of Representatives.")
else :
print ("The candidate is not eligible for either of the posts.")
main()
============== RESTART: D:/college/Final Exam/Program_3.py ==============
Enter the age: 25
for How long you have being the citizen of USA? 18
The candidate is eligible to be a member of the U.S. House of Representatives.
>>> 
Download