VND - Openxmlformats Officedocument - Wordprocessingml.document&rendition 1
VND - Openxmlformats Officedocument - Wordprocessingml.document&rendition 1
OUTPUT:
Enter first number : 4
Enter second number : 2
4 is divisible by 2
Output
Enter an integer : 8
8 is even number.
Enter operator [ + - * / % ] : *
Enter a number : 6
**
***
****
OUTPUT:
***
***
***
1
1
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
Enter a number:407
17.Write a program that reads a string and checks whether it is a palindrome string
or not using string slice.
Solutions :
2 to the power 3 is 8
7 !! is: 105
OUTPUT:
13
135
1357
# 21: Write a Python script that traverses through an input
string and prints its characters in different lines — two
characters per line.
str = input("Enter the string: ")
length = len(str)
for a in range(0, length, 2):
print(str[a:a+2])
OUTPUT:
Co
mp
ut
er
O occurs 1 times
OUTPUT:
C*mp*t*r Sc**nc*
OUTPUT:
MAGORPNOHTYP
OUTPUT:
Enter a number: 10
for i in range(len(l1)):
l2.append(l1[i][1:])
OUTPUT:
OUTPUT:
OUTPUT:
Enter a tuple:(1,1,12,23,2,4,5,4,6,4,3,5,8)
Mode: 4
OUTPUT:
Enter tuple:(12,23,55,14,89)
for i in range(n):
name = input("Enter the name of student: ")
roll_num = int(input("Enter the roll number of student: "))
marks = int(input("Enter the marks of student: "))
grade = input("Enter the grade of student: ")
details[roll_num] = [name, marks, grade]
print()
print(details)
OUTPUT:
{1: ['3', 98, 'A'], 2: ['ASHIS', 78, 'A'], 3: ['BIPIN', 90, 'A'], 4: ['ANJANA', 87, 'C'], 5:
['ROHIT', 89, 'A'], 6: ['RENU', 96, 'D'], 7: ['ASNI', 76, 'C'], 8: ['BHINU', 56, 'B'], 9:
['RANJAN', 90, 'A'], 10: ['BIBHN', 94, 'A']}
OUTPUT:
['This', 'is', 'a', 'super', 'idea', 'This', 'idea', 'will', 'change', 'the', 'idea', 'of', 'learning']
"This": 2,
"is": 1,
"a": 1,
"super": 1,
"idea": 3,
"will": 1,
"change": 1,
"the": 1,
"of": 1,
"learning": 1
Q32: Write a program to convert a number entered by the user into its corresponding
number in words. For example, if the input is 876 then the output should be 'Eight
Seven Six'.
(Hint. use dictionary for keys 0-9 and their values as equivalent words.)
digit = 0
str = ""
digit = num % 10
num = num // 10
print(str)
output:
Enter a number: 56
Five Six
Enter a number: 89
Eight Nine
Q33. Write a program to create a nested tuple to store roll number, name and marks
of students.
tup = ()
ans = "y"
print(tup)
if n in l:
else :
--------------------------
40 found at index 3
Q35: Write a program that inputs a line of text and prints out the count of vowels in it.
count = 0
for ch in str :
lch = ch.lower()
if lch == 'a' \
or lch == 'e' \
or lch == 'i' \
or lch == 'o' \
or lch == 'u' :
count += 1
Vowel Count = 6