Whether The Given Input Is A Character or A Digit, If The Input Is 0 Exit The Program, Otherwise Print The Result. Ans
Whether The Given Input Is A Character or A Digit, If The Input Is 0 Exit The Program, Otherwise Print The Result. Ans
Whether The Given Input Is A Character or A Digit, If The Input Is 0 Exit The Program, Otherwise Print The Result. Ans
Ans =
while True:
if user_input == '0':
break
elif user_input.isalpha():
elif user_input.isdigit():
else:
2. Write a Python program to count the vowels and consonants in the string, which is
inputted from the user.
Ans =
vowel_count = 0
consonant_count = 0
if char.lower() in 'aeiou':
vowel_count += 1
consonant_count += 1
3. Write a Python program to convert Fahrenheit into Celsius. The formula of Fahrenheit
conversion into celsius is: C= ((fahrenheit-32)*5)/9. Print the result.
Ans =
4. Write a Python program to calculate Factorial of user input data by using the recursion concept.
Print the result.
Ans =
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
if num < 0:
elif num == 0:
else:
Ans =
def is_armstrong(num):
num_str = str(num)
num_digits = len(num_str)
sum = 0
if sum == num:
return True
else:
return False
# take input from the user
if is_armstrong(num):
else:
6. write a python program to enter 3*3 matrix from the console and also print transpose of it
Ans =
matrix = []
for i in range(3):
row = input("Enter row " + str(i+1) + " (separate the numbers with spaces): ")
print("Original matrix:")
print(row)
transpose = []
for i in range(3):
row = []
for j in range(3):
row.append(matrix[j][i])
transpose.append(row)
# print the transpose of the matrix
print(row)
The program has a function sayhello() It takes a single argument which is a string.
The argument inside the parenthesis of the function is username We end the header with a colon:
Inside the function create a variable greet and assign a value "Hello"
Let us look at the reusability of the function. Let us create a list of names to whom we want to
print the greeting
L1 [Ram', 'Mahesh', Vasudha', 'Uma', 'Sekhar, John"] Let's call the function by passing the items of
the list as argument and print the result
greet = "Hello"
# list of names
sayhello(name)
8. write a python program to check whether the user input integer is leap year is not.
Ans=
if year % 100 == 0:
if year % 400 == 0:
else:
else:
else:
Ans=
if b == 0:
return a
else:
return gcd(b, a % b)
# calculate the GCD of the two numbers using the defined function
Ans=
class Person:
self.name = name
def getName(self):
return self.name
p1 = Person()
p2 = Person()
p1.setName(name1)
p2.setName(name2)