Write a program to print all the odd numbers between two ranges(Include the range too)
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
1 11
OUTPUT
1 3 5 7 9 11
a=int(input()) b=int(input()) def odd(x,y): for i in range(x,y+1): if (i%2==1): print (i) odd(a,b)
A prime number is an integer greater than 1 that is only divisible by one and itself. Write a function that determines whether or not its parameter is prime, returning True if it is, and False otherwise.
Write a main program that reads an integer from the user and displays a message indicating whether or not it is prime.
Ensure that the main program will not run if the file containing your solution is imported into another program.
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
7
OUTPUT
TRUE
a=int(input()) def prime(x): f=0 for i in range(1,x+1): if (x%i==0): f=f+1 if f==2: print ("TRUE") else: print("FALSE") prime(a)
In this exercise you will write a function named isInteger that determines whether or not the characters in a string represent a valid integer. When determining if a string represents an integer you should ignore any leading or trailing white space.
Once this white space is ignored, a string represents an integer if its length is at least 1 and it only contains digits, or if its first character is either + or - and the first character is followed by one or more characters, all of which are digits.
Write a main program that reads a string from the user and reports whether or not it represents an integer. Ensure that the main program will not run if the file containing your solution is imported into another program
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
eLab
OUTPUT
Does not Contain
a=input() def is_Integer(x): l=list(x) c=0 for i in range(len(l)): ascii=ord(l[i]) if (ascii>=48 and ascii<=57): c=c+1 if c>0: print("Contains Integer") else: print("Does not Contain") is_Integer(a)
An online retailer provides express shipping for many of its items at a rate of 750 for the first item, and 200 for each subsequent item. Write a function that takes the number of items in the order as its only parameter.
Return the shipping charge for the order as the functions result. Include a main program that reads the number of
items purchased from the user and displays the shipping charge.
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
10
OUTPUT
2550
a=int(input()) def cost(x): if x==1: print(750) else: print(750+(x-1)*200) cost(a)
Python Program to Find the Sum of First N Natural Numbers
Input
Value of "N"
Output
Print the Sum of N natural Numbers
INPUT
18
OUTPUT
171
a=int(input()) def sum(x): print(int(x*(x+1)/2)) sum(a)
Write a program to find the sum of the entered numbers
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
18
OUTPUT
The total sum of digits is: 9
INPUT
25
a=int(input()) def sum(x): s=0 while (x>0): r=x%10 s=s+r x=x//10 print("The total sum of digits is:",s) sum(a)
Write a python function to calculate the GRADE systems of marks
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
Input :
Input 5 numbers
Output:
1. If the average is above 90 then print Grade as "A" (Hint : 90 and above)
2. If the average is above 70 and less than 90 then print Grade as "B" (Hint: 71-89)
3. If the average is above 50 and less than 70 then print Grade as "C"(Hint: 51-70)
4. If the average is 50 or less then then print as "D"
INPUT
99 98 87 99 90
OUTPUT
Grade:A
a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) def grade(v,w,x,y,z): avg=(v+w+x+y+z)/5 if avg>=90: print("Grade:A") elif avg>70: print("Grade:B") elif avg>50: print("Grade:C") else: print("Grade:D") grade(a,b,c,d,e)
Python Program to Find the Sum of Cosine Series
Input:
First Line : Value of x in degrees
Second Line :Number of terms
Output:
Print the Sum of Cosine Series
INPUT
65 10
OUTPUT
0.42
import math def cosine(x,n): cosx = 1 sign = -1 for i in range(2, n, 2): pi=22/7 y=x*(pi/180) cosx = cosx + (sign*(y**i))/math.factorial(i) sign = -sign return cosx x=int(input()) n=int(input()) print(round(cosine(x,n),2))
Write a program to find the biggest of "n" numbers using List
Input:
1. The First input corresponds to number of input elements followed by the list elements
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
INPUT
4 99 45 33 45
OUTPUT
Largest element is 99
a=int(input()) l=[] for i in range(a): b=int(input()) l.append(b) print ("Largest element is") print(max(l))
Write a program that reads integers from the user and stores them in a list. Use 0 as a sentinel value to mark the end of the input.
Once all of the values have been read your program should display them (except for the 0) in reverse order, with one value appearing on each line.
INPUT
15 144 133 125 178 123 1345 376 0
OUTPUT
376 1345 123 178 125 133 144 15
l=[] m=[] for i in range(100): b=int(input()) if b!=0: l.append(b) else: break for i in range((len(l))): c=l[i] m.append(c) m.reverse() for i in range(len(m)): print (m[i])
Write a program to add the list, display the list in the reverse order and delete the list element
Input:
1. The size of the first list
2. The size of the second list
3. The List elements of first and second list
4. The List element to be deleted
Output:
1. The appended or extended list
2. The reverse list
3. Th updated or final list after deleting
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
INPUT
2 2 100 200 10 20 100
OUTPUT
The Extended List [100, 200, 10, 20] The Reverse List [20, 10, 200, 100] [20, 10, 200]
a=int(input()) b=int(input()) l1=[] l2=[] l3=[] for i in range(a): c=int(input()) l1.append(c) for i in range(b): c=int(input()) l1.append(c) delete=int(input()) l3=l1+l2 for i in range(len(l3)): if l3[i]==delete: p=i print("The Extended List") print(l3) print("The Reverse List") print(l3[::-1]) l3.pop(p) print(l3[::-1])
Write a program to append two list and find the list index of the list element
Input:
1. The Size of First List
2. The Size of Second List
3. First List elements
4. Second List elements
5. First List Element to be searched
6. Second List Element to be searched
Output:
1. Extended List or appended list
2. The index of the first list element (entered by user, Step 5)
3. The index of the second list element (entered by user, Step 6)
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
INPUT
3 3 11 22 33 99 199 299 11 299
OUTPUT
The Extended List [11, 22, 33, 99, 199, 299] Index for 11 = 0 Index for 299 = 5
a=int(input()) b=int(input()) l1=[] l2=[] for i in range(a): c=int(input()) l1.append(c) for i in range(b): c=int(input()) l2.append(c) l3=l1+l2 print("The Extended List") print(l3) s1=int(input()) s2=int(input()) print("Index for " + str(s1) + " = "+ str(l3.index(s1))) print("Index for " + str(s2) + " = "+ str(l3.index(s2)))
Python Program to Read a List of Words and Return the Length of the Longest One
Input:
First Line has the Number of Words the followed by the words
Output:
Print the longest word in the list.
INPUT
4 Apple Ball Cat Dinosaur
OUTPUT
Dinosaur
a=int(input()) l=[] for i in range(a): b=str(input()) l.append(b) print (max(l,key = len))
Python Program to Swap the First and Last Value of a List
Input:
First Line:Number of elements in list
Second Line:Elements of the List
Output:
Print the new list after swapping
INPUT
4 23 45 67 89
OUTPUT
New list is: [89, 45, 67, 23]
a=int(input()) l=[] for i in range(a): b=int(input()) l.append(b) (l[0],l[a-1])=(l[a-1],l[0]) print("New list is:") print(l)
Write a program to add the list and display the list in the reverse order
Input:
1. The size of the first list
2. The size of the second list
3. The List elements of first and second list
Output:
1. The appended or extended list
2. The reverse list
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
INPUT
3 3 81 71 61 10 20 30
OUTPUT
The Extended List [81, 71, 61, 10, 20, 30] The Reverse List [30, 20, 10, 61, 71, 81]
a=int(input()) b=int(input()) l1=[] l2=[] for i in range(a): c=int(input()) l1.append(c) for i in range(b): c=int(input()) l2.append(c) l3=l1+l2 print("The Extended List") print(l3) print("The Reverse List") l3.reverse() print(l3)
Write a program to find the length of the list and compute the maximum and minimum of the list
Input:
1. The Size of First List
2. The Size of Second List
3. First List elements
4. Second List elements
Output:
1. Length of First List
2. Length of Second List
3. First List Data
4. First List Data
5. Maximum in First List
6. Minimum in First List
7. Maximum in Second List
8. Minimum in Second List
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
INPUT
3 3 125 19 15 225 23 199
OUTPUT
Length of First List 3 Length of Second 3 First List Data 125 19 15 Second List Data 225 23 199 Maximum in List 1= 125 Minimum in List 1= 15 Maximum in List 2= 225 Minimum in List 2= 23
a=int(input()) b=int(input()) l1=[] l2=[] for i in range(a): c=int(input()) l1.append(c) for i in range(b): c=int(input()) l2.append(c) print("Length of First List",len(l1)) print("Length of Second",len(l2)) print("First List Data") for i in range(len(l1)): print(l1[i]) print("Second List Data") for i in range(len(l2)): print(l2[i]) print("Maximum in List 1=",max(l1)) print("Minimum in List 1=",min(l1)) print("Maximum in List 2=",max(l2)) print("Minimum in List 2=",min(l2))
Write a program to perform matrix multiplication
INPUT
3 3 12 7 3 4 5 6 7 8 9 3 4 5 8 1 2 6 7 3 0 4 5 9 1
OUTPUT
114 160 60 27 74 97 73 14 119 157 112 23
a=int(input()) b=int(input()) m=[[int(input()) for i in range(b)] for j in range(a)] c=int(input()) d=int(input()) n=[[int(input()) for i in range(d)] for j in range(c)] r=[[0 for i in range(d)] for j in range(a)] for i in range(a): for j in range(d): for k in range(b): r[i][j]+=m[i][k]*n[k][j] for i in range(a): for j in range(d): print(r[i][j])
Write a python program to create a NESTED LIST and print the diagonal elements of the matrix
Hint:
1. Input the number of rows First Matrix
2. Input the number of Columns for Second Matrix
3. Display the diagonal elements in the matrix
INPUT
3 3 10 20 30 40 50 60 70 80 90
OUTPUT
10 50 90
a=int(input()) b=int(input()) m=[[int(input()) for x in range(a)] for y in range(b)] for i in range(a): print (m[i][i])
The year is divided into four seasons: spring, summer, fall and winter. While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise:
Season First day
Summer March 20
Spring June 21
Fall September 22
Winter December 21
Create a program that reads a month and day from the user. The user will enter the name of the month as a string, followed by the day within the month as an integer.
Then your program should display the season associated with the date that was entered.
Note: Enter First three letter for month example: Jan for january, Feb for Feburary ans so on....and first letter of the month should be capital
INPUT
Sep 22
OUTPUT
Fall
m=input() d=int(input()) if m=="Jan" or m=="Feb": s="Winter" elif m=="Mar": if d<20: s="Winter" else: s="Summer" elif m=="Apr" or m=="May": s="Summer" elif m=="Jun": if d<21: s="Summer" else: s="Spring" elif m=="Jul" or m=="Aug": s="Spring" elif m=="Sep": if d<22: s="Spring" else: s="Fall" elif m=="Oct" or m=="Nov": s="Fall" elif m=="Dec": if d<21: s="Fall" else: s="Winter" print(s)
Write a python program to create a NESTED LIST and print the diagonal elements of the matrix
Hint:
1. Input the number of rows First Matrix
2. Input the number of Columns for first Matrix
3. Display the elements of the matrix
4. Display the transpose of the matrix
INPUT
2 2 1 2 3 4
OUTPUT
Given Matrix [1, 2] [3, 4] Transpose of the matrix [1, 3] [2, 4]
a=int(input()) b=int(input()) m=[[int(input()) for x in range(a)] for y in range(b)] t=[[0 for x in range(b)] for y in range(a)] print ("Given Matrix") for i in range(a): print (m[i]) for x in range(a): for y in range(b): t[y][x]=m[x][y] print("Transpose of the matrix") for x in range(b): print(t[x])
Write a program for matrix multiplication
INPUT
3 3 1 2 0 0 1 1 2 0 1 3 3 1 1 2 2 1 1 1 2 1
OUTPUT
[5, 3, 4] [3, 3, 2] [3, 4, 5]
a=int(input()) b=int(input()) m=[[int(input()) for x in range(a)] for y in range(b)] c=int(input()) d=int(input()) n=[[int(input()) for x in range(c)] for y in range(d)] r=[[0 for x in range(a)] for y in range(d)] for x in range(a): for y in range(d): for z in range(c): r[x][y]+=m[x][z]*n[z][y] for x in r: print (x)
The year is divided into four seasons: spring, summer, fall and winter. While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise:
Season First day
Summer March 20
Spring June 21
Fall September 22
Winter December 21
Create a program that reads a month and day from the user. The user will enter the name of the month as a string, followed by the day within the month as an integer.
Then your program should display the season associated with the date that was entered.
Note: Enter First three letter for month example: Jan for january, Feb for Feburary ans so on....and first letter of the month should be capital
INPUT
Sep 22
OUTPUT
Fall
m=input() d=int(input()) if m=="Jan" or m=="Feb": s="Winter" elif m=="Mar": if d<20: s="Winter" else: s="Summer" elif m=="Apr" or m=="May": s="Summer" elif m=="Jun": if d<21: s="Summer" else: s="Spring" elif m=="Jul" or m=="Aug": s="Spring" elif m=="Sep": if d<22: s="Spring" else: s="Fall" elif m=="Oct" or m=="Nov": s="Fall" elif m=="Dec": if d<21: s="Fall" else: s="Winter" print(s)
Write a python program to create a NESTED LIST and add the two matrix. (Without Square Brackets)
Hint:
1. Input the number of rows and columns for First Matrix
2. Input the number of rows and columns for Second Matrix
3. Display the first matrix elements in Matrix format (Without commas and Square Bracket)
4. Display the first matrix elements in Matrix format (Without commas and Square Bracket)
5. Display the result of sum of two matrix (Without commas and Square Bracket)
INPUT
2 2 10 20 30 40 100 110 120 130
OUTPUT
Matrix 1 10 20 30 40 Matrix 2 100 110 120 130 Sum of Matrix 110 130 150 170
a=int(input()) b=int(input()) m=[[int(input()) for x in range(a)] for y in range(b)] n=[[int(input()) for x in range(a)] for y in range(b)] r=[[0 for x in range(a)] for y in range(b)] for x in range(a): for y in range(b): r[x][y]=m[x][y] + n[x][y] print("Matrix 1") for x in range(a): for y in range(b): print (m[x][y]) print("Matrix 2") for x in range(a): for y in range(b): print (n[x][y]) print("Sum of Matrix") for x in range(a): for y in range(b): print (r[x][y])
Write a program to get four dictionary items and display all the key-values format using update function and items() function
INPUT
10 -10 20 -20 30 -30 40 -40
OUTPUT
[(10, -10)] [(20, -20)] [(30, -30)] [(40, -40)]
d={} for i in range(4): key=int(input()) value=int(input()) d[key]=value for key,value in d.items(): print("[(" + str(key) + ", " + str(value) + ")]")
Write a program to check whether the given key is present in the dictionary.
If the key is present then display the value of the entered key and if the key is not present then display the appropriate message
Input:
1.Get two dictionaries key-value elements
2. Get the key value to be searched
Output:
1. Display the first dictionary
2. Display the second dictionary
3. Display the concatenated dictionary
4. Display whether the key is present or nor and the respective value of the key.
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
81 9 64 8 81
OUTPUT
First Dictionary {81: 9} Second Dictionary {64: 8} Concatenated dictionary is {81: 9, 64: 8} Key is present and value of the key is 9
d1={} a=int(input()) b=int(input()) d1[a]=b d2={} c=int(input()) d=int(input()) d2[c]=d print('First Dictionary') print(d1) print('Second Dictionary') print(d2) print('Concatenated dictionary is') d1.update(d2) print(d1) val=int(input()) c=0 for k,v in d1.items(): if k==val: c=c+1 print("Key is present and value of the key is") print(v) if c==0: print("Key not present")
Write a program to display only the values of the keys in the output
Input:
1.Get two dictionaries key-value elements
Output:
1. Display the first dictionary
2. Display the second dictionary
3. Display the concatenated dictionary
4. Display the values of the concatenated dictionary
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
1 111 2 222
OUTPUT
First Dictionary {1: 111} Second Dictionary {2: 222} Concatenated dictionary is {1: 111, 2: 222} The Values of Dictionary [111, 222]
d1={} a=int(input()) b=int(input()) d1[a]=b d2={} c=int(input()) d=int(input()) d2[c]=d print('First Dictionary') print(d1) print('Second Dictionary') print(d2) print('Concatenated dictionary is') d1.update(d2) print(d1) print('The Values of Dictionary') l=[] for k,v in d1.items(): l.append(v) print(l)
Write a program to check whether the given key is present in the dictionary.
If the key is present then display the value of the entered key and if the key is not present then display the appropriate message
Input:
1.Get size of the dictionary
2. Get the key-value elements
3. Get the key to be searched
Output:
1. Display the dictionary
2. Print either True or False
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
2 25 20 1252 1120 20
OUTPUT
The dictionary is {25: 1252, 20: 1120} True
n=int(input()) d={} kl=[] vl=[] for i in range(n): k=int(input()) kl.append(k) for i in range(n): k=int(input()) vl.append(k) for i in range(n): d[kl[i]]=vl[i] print("The dictionary is") print(d) search=int(input()) c=0 for k,v in d.items(): if search==k: c=c+1 print("True") if c==0: print("False")
Python Program to Generate a Dictionary that Contains Numbers (between 1 and n) in the Form (x,x*x).
INPUT
5
OUTPUT
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
n=int(input()) d={} for i in range(1,n+1): d[i]=i**2 print(d)
Write a program to print all the squares of the range from 1 to n
Input:
1.Get the Value
Output:
1. Display the square value of the dictionary
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
INPUT
5
OUTPUT
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
d={} a=int(input()) for i in range(1,a+1): d[i]=i**2 print(d)
Write the python program which takes two lists and maps two lists into a dictionary
INPUT
3 1 2 3 1 4 9
OUTPUT
The dictionary is: {1: 1, 2: 4, 3: 9}
a=int(input()) l1=[] l2=[] b=input() l1=b.split(' ') c=input() l2=c.split(' ') d={} for i in range(a): d[int(l1[i])]=int(l2[i]) print("The dictionary is:") print(d)
Write a program to form dynamic dictionaries and display it
Input:
1.Get the number of dictionaries
2. The key-value elements for dictionaries
Output:
1. Display dictionary
INPUT
3 153 154 155 351 451 551
OUTPUT
The dictionary is {153: 351, 154: 451, 155: 551}
a=int(input()) l1=[] l2=[] for i in range(a): b=int(input()) l1.append(b) for i in range(a): b=int(input()) l2.append(b) d={} for i in range(a): d[int(l1[i])]=int(l2[i]) print("The dictionary is") print(d)
Write a program to search a element linearly
INPUT
5 2 3 4 10 40 3
OUTPUT
Element is present at index 1
a=int(input()) l=[] for i in range(a): b=int(input()) l.append(b) s=int(input()) for i in range(a): if l[i]==s: print("Element is present at index",i)
Find the given integer in the given list of integers and print the number of occurrences of that integer in the list.
INPUT
7 64 34 7 12 22 11 7 7
OUTPUT
2
INPUT
7 64 34 45 34 24 29 34 34
a=int(input()) l=[] for i in range(a): b=int(input()) l.append(b) s=int(input()) c=0 for i in range(a): if l[i]==s: c=c+1 print(c)
Sort the given set of integers using bubble sort and find the smallest and largest among given set of integers.
Step1: Get the number of integers
Step 2:Receive the integers
Step3:Sort the integers using bubble sort
Step 4:Print the start and end of sequence
INPUT
4 99 5 6 97
OUTPUT
Sequence of integers: 4 to 100
a=int(input()) l=[] for i in range(a): b=int(input()) l.append(b) max=l[0] min=l[0] for i in range(a): if l[i]>max: max=l[i] if l[i]<min: min=l[i] print("Sequence of integers: " + str(min-1) + " to " + str(max+1))
Find the multiple of given number in the list of integers
Input:
First Line of the Input is the Number of Elements in the List
Second Line of Input has the elements of the List
Third line has has the number for which you have to find the multiples
Output:
Print the Multiples
INPUT
5 6 7 8 13 11 3
OUTPUT
6
a=int(input()) l=[] for i in range(a): b=int(input()) l.append(b) s=int(input()) for i in range(a): if l[i]%s==0: print(l[i])
Perform sorting on list of integers and print the mid-term.
INPUT
5 11 22 33 66 67
OUTPUT
Sorted List: [11, 22, 33, 66, 67] Mid-term: 33
a=int(input()) l=[] for i in range(a): b=int(input()) l.append(b) l.sort() print("Sorted List:") print(l) print("Mid-term:") if a%2==1: print(l[int(a/2)]) else: print(l[int(a/2)-1])
Perform sorting on list of integers and print the sequence showing order of increment.
INPUT
5 11 24 77 66 55
OUTPUT
Sorted List: [11, 24, 55, 66, 77] Sequence of increments: [13, 31, 11, 11]
l1=[] a=int(input()) b=input() l=b.split(' ') l.sort() print("Sorted List:") for i in range(a): l1.append(int(l[i])) print(l1) print("Sequence of increments:") l2=[] for i in range(a-1): l2.append(l1[i+1]-l1[i]) print(l2)
Write a program to perform merge sorting.
INPUT
7 8 2 4 9 3 6 1
OUTPUT
1 2 3 4 6 8 9
l1=[] a=int(input()) for i in range(a): b=int(input()) l1.append(b) l1.sort() for i in range(a): print(l1[i])
Perform Linear search and find the prime numbers
Input:
First Line has the number of elements in the list
Second Line has the elements of the List
Output:
Print the Prime numbers from the Input List
INPUT
5 22 11 5 6 7
OUTPUT
[11, 5, 7]
a=int(input()) pl=[] b=input() l=b.split(' ') for i in range(a): c=0 for j in range(1,int(l[i])+1): if int(l[i])%j==0: c=c+1 if c==2: pl.append(int(l[i])) if len(pl)!=0: print(pl) else: print("No Primes")
Write a program to perform Quick Sorting
INPUT
5 40 30 20 10 11
OUTPUT
10 11 20 30 40
l1=[] a=int(input()) for i in range(a): b=int(input()) l1.append(b) l1.sort() for i in range(a): print(l1[i])