PYTHON ASSIGNMENT 2
Program_01 : Write a program which will find all such numbers which are divisible by 7 but are not
a multiple of 5,between 2000 and 3200 comma separated sequence on a single line.
for i in range(2000,3200):
if (i%7==0) and (i%5!=0):
print(i,end=", ")
OUTPUT :
2002, 2009, 2016, 2023, 2037, 2044, 2051, 2058, 2072, 2079, 2086, 2093, 2107, 2114, 2121, 2128,
2142, 2149, 2156, 2163, 2177, 2184, 2191, 2198, 2212, 2219, 2226, 2233, 2247, 2254, 2261, 2268,
2282, 2289, 2296, 2303, 2317, 2324, 2331, 2338, 2352, 2359, 2366, 2373, 2387, 2394, 2401, 2408,
2422, 2429, 2436, 2443, 2457, 2464, 2471, 2478, 2492, 2499, 2506, 2513, 2527, 2534, 2541, 2548,
2562, 2569, 2576, 2583, 2597, 2604, 2611, 2618, 2632, 2639, 2646, 2653, 2667, 2674, 2681, 2688,
2702, 2709, 2716, 2723, 2737, 2744, 2751, 2758, 2772, 2779, 2786, 2793, 2807, 2814, 2821, 2828,
2842, 2849, 2856, 2863, 2877, 2884, 2891, 2898, 2912, 2919, 2926, 2933, 2947, 2954, 2961, 2968,
2982, 2989, 2996, 3003, 3017, 3024, 3031, 3038, 3052, 3059, 3066, 3073, 3087, 3094, 3101, 3108,
3122, 3129, 3136, 3143, 3157, 3164, 3171, 3178, 3192, 3199,
Program_02 : Write a program which can compute the factorial of a given numbers. The results
should be printed in a comma-separated sequence on a single line.Suppose the following input is
supplied to the program: 8 Then, the output should be: 40320
number = int(input("Enter the number you want to get the factorial of : "))
product = 1
for i in range(1,number+1):
product = product*i
print("The Factorial of ",number," is : ",product)
OUTPUT :
The Factorial of 8 is : 40320
Program_03 : Given a range of first 10 numbers, Iterate from start number to the end number and
print the sum of the current number and previous number.
print("The sum of Current and Previous Number between range (1,10) is : ")
for i in range(1,11):
print("[",i,"+",i-1,"=",i+(i-1),"]\n",end="")
OUTPUT :
The sum of Current and Previous Number between range (1,10) is :
[1+0=1]
[2+1=3]
[3+2=5]
[4+3=7]
[5+4=9]
[ 6 + 5 = 11 ]
[ 7 + 6 = 13 ]
[ 8 + 7 = 15 ]
[ 9 + 8 = 17 ]
[ 10 + 9 = 19 ]
Program_04 : Given a string, display only those characters which are present at an even index
number. For example str = "pynative" so you should display 'p','n','t','v'.
string = 'pynative'
str = len(string)
for i in range(str):
if(i%2==0):
print("'",string[i],"',",end="")
OUTPUT :
' p ',' n ',' t ',' v ',
Program_05 : Return the total count of sub-string “Emma” appears in the given string. Given string
is “Emma is good developer. Emma is a writer”
string = 'Emma is good developer. Emma is a writer'
str = string.count("Emma")
print("'Emma' is printted ",str," times in the string.")
OUTPUT :
'Emma' is printted 2 times in the string.
Program_06 : Write a program that computes and prints the result of 512−28247.48+5.
sum = 512 - 28247.48 + 5
print(sum)
OUTPUT :
-27730.48
Program_07 : Ask the user to enter a number. Print out the square of the number.
number = int(input("Enter the number you want the square of : "))
square = number**2
print("The square of the number is : ",square)
OUTPUT:
The square of the number is : 81
Program_08 : Write a program that asks the user to enter three numbers (use three separate input
statements). Create variables called total and average that hold the sum and average of the three
numbers and print out the values of total and average.
number_01 = int(input("Enter the first number : "))
number_02 = int(input("Enter the second number : "))
number_03 = int(input("Enter the third number : "))
total = number_01+number_02+number_03
average = total/3
print("The total sum of the numbers entered
(",number_01,"+",number_02,"+",number_03,") is : ",total)
print("The total average of the numbers entered is :
",format(average,'.2f'))
OUTPUT :
The total sum of the numbers entered ( 4 + 6 + 7 ) is : 17
The total average of the numbers entered is : 5.67
Program_09 : Write a program that uses a for loop to print the numbers 8, 11, 14, 17, 20,. . . , 83,
86, 89.
for i in range(8,90,3):
print(i,", ",end="")
OUTPUT:
8 , 11 , 14 , 17 , 20 , 23 , 26 , 29 , 32 , 35 , 38 , 41 , 44 , 47 ,
50 , 53 , 56 , 59 , 62 , 65 , 68 , 71 , 74 , 77 , 80 , 83 , 86 , 89 ,
Program_10 : Write a program that uses a for loop to print the numbers 100, 98, 96, . . . , 4, 2.
for i in range(100,1,-2):
print(i,", ",end="")
OUTPUT:
100 , 98 , 96 , 94 , 92 , 90 , 88 , 86 , 84 , 82 , 80 , 78 , 76 , 74 ,72 , 70 , 68 , 66 , 64 , 62 , 60 , 58 , 56 , 54
, 52 , 50 , 48 , 46 ,44 , 42 , 40 , 38 , 36 , 34 , 32 , 30 , 28 , 26 , 24 , 22 , 20 , 18 ,16 , 14 , 12 , 10 , 8 , 6 , 4
,2