0% found this document useful (0 votes)
12 views

Ge Python

The document contains Python code snippets for various string and number operations like reversing a string, removing vowels from a string, calculating average of marks, checking if a character is vowel or consonant, printing Fibonacci series, checking palindrome number, comparing two characters. For each operation, it shows example input/output.

Uploaded by

Tanvi Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Ge Python

The document contains Python code snippets for various string and number operations like reversing a string, removing vowels from a string, calculating average of marks, checking if a character is vowel or consonant, printing Fibonacci series, checking palindrome number, comparing two characters. For each operation, it shows example input/output.

Uploaded by

Tanvi Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

14.Write a user defined function in python to reverse a string.

def string(x): reverse=x[::-1] return reverse


x=input("enter Computer:") string(x)

OUTPUT:- enter Computer:APPLE


ELPPA

15. Program to display vowels form string.

string = input("Enter the string : ") vowels = ['a', 'e', 'i', 'o',
'u', 'A', 'E',
'I', 'O', 'U'] result = "" for i in range(len(string)): if
string[i] not in vowels: result = result + string[i]
print("\nAfter removing Vowels: ",result)

OUTPUT:-
Enter the string : you are brave

After removing Vowels: y r brv


16.Write a Program that accepts marks in 5 subjects and output average marks.
marks1 = int(input("Enter first subject marks:")) marks2 =
int(input("Enter second subject marks:")) marks3 =
int(input("Enter third subject marks:")) marks4 =
int(input("Enter fourth subject marks:")) marks5 =
int(input("Enter fifth subject marks:")) avg = (marks1 + marks2+
marks3+ marks4 + marks5) / 5 print("Average Marks =", avg)

OUTPUT:- Enter first subject marks:67


Enter second subject marks:86
Enter third subject marks:94
Enter fourth subject marks:74
Enter fifth subject marks:84
Average Marks = 81.0

17.Write a Program to accept a character from the user and display whether it is a vowel or consonant.
ch = input("Enter a character: ") if(ch=='A' or ch=='a' or
ch=='E' or ch =='e' or ch=='I' or ch=='i' or ch=='O' or
ch=='o' or ch=='U' or ch=='u'):
print(ch, "is a Vowel") else:
print(ch, "is a Consonant")

OUTPUT:-
Enter a character: A
A is a Vowel

Enter a character: G G is a Consonant


18.Write a Program to print Fibonacci series up to a certain limit.
n = int(input("Enter the value of 'n': "))
a = 0 b = 1 sum = 0 count = 1
print("Fibonacci Series: ", end
= " ")
while(count <=
n):
print(sum, end = " ")
count += 1 a = b b =
sum sum = a + b

OUTPUT:-
Enter the value of 'n': 10
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34

19. Write a Program to accept a number and check whether that number palindrome or not.
n=int(input("Enter number:")) temp=n rev=0
while(n>0): dig=n%10 rev=rev*10+dig n=n//10
if(temp==rev):
print("The number is a palindrome!") else:
print("The number isn't a palindrome!")

OUTPUT:- Enter number:44


The number is a palindrome!
20. Program that takes two char arguments and returns True if both the arguments are equal otherwise
False.
def chr(char1,char2) : if char1 == char2 :
return "True" else:
return"False "
char1 = input("Enter a Char 1 : ") char2 = input("Enter a Char 2 : ")
print(chr(char1,char2))

OUTPUT:-
Enter a Char 1 : india
Enter a Char 2 : india True

You might also like