0% found this document useful (0 votes)
17 views6 pages

Adobe Scan 13-May-2024

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

Adobe Scan 13-May-2024

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

print ("0riginalString :", string)

string2)
print ("Captilized words String",
string and checks whether it is a palindrone string or not.
8. Write aprogram that reads a
V Solution. :")
string = input ("Enter a string
length = len(string)
mid = length/2
rev = 1

for a in range(mid): string[rev] :


if string[a] ==
a+=1
rev-= 1

else : palindrome")
print(string, "is not a
break
#l0op else
apalindrome")
else:
print (string, "is
when both are sequences ?
different from strings XAinã WaVS:
DATE:
CREATING APYTHONPROGRAM TO DISPLAY FIBONACCL SERIES

AIM:
To write a Python Program to display Fibonacci Series up to 'n' numbers.

SOURCE CODE:
First=0
Second=1
no=int (input("How many Fibonacci numbers you want to display?"))
if no<=0:
print ("Please Enter Positive Integer")

else:
print (First)
print (Second)
for i in range (2, no) :
Third=First+Second
First=Second
Second=Third
print (Third)
Result:
Thus, the above Python program has been executed and the output is verified
successfully.

SAMPLE QUTPUT:
Python Executed Program Qutput:

How many Fibonacci numbers you want to display?8


0
1
1
2
3

8
13
EXNO:6

DATE:
CREATING APYTHON PROGRAM TO GENERATE RANDOM NUMBER
BETWEEN 1 TO 6

AIM:
between 1 to 6 to simulate
To write a Python program to generate random number
the dice.

SQURCE CODE:

import random
while True:
Choice=input ("\nDo you want to roll the dice (y/n) : ")
no=random. randint (1,6)
if Choice=='y':
print ("\nYour Number is:",no)
else:
break

Result:
Thus, the above Python program has been executed and the output is verified
successfully.

SAMPLE QUTPUT:
Python ExecutedOutput Program:
Do you want tO roll the dice (y/n) :y
Your Number is: 5

po you want to roll the dice (y/n) :y


Your Number is: 2

Do you want to roll the dice (y/n) :y


Your Number is: 1

Do you want to roll the dice (y/n) :n


kkkk*****:

11)
Q5.Write a program to input a character and to print
whether a given character is an alphabet, digit or any
other character.
Ans:
Spyder (ython 3.7)
File Edit Search Source Run Debug Consoles Projects Toos View Help

Editor - C:Usersladmin\Desktoplalpha.py
ortant.py 3 connectivity.py prime number.py compound interest.py asci.py algha.py X 4
1 char=input ("Enter a character:")
2 if char.isalpha():
print (" Entered character is alphabet")
4 elif char. isdigit():
5 print ("Entered character is digit")
6 else:
7 print (" Entered character is a special character")
8

Output:
In [12]: runfile('C:/Users/admin/Desktop/alpha. py'.
wdir='c:/Users/a dmin/Desktop')
Enter a character:r
Entered character is alphabet

In [13] : runfile('C:/Users/admin/ Desktop/alpha . py',


wdir='C:/Users/admin/Desktop' )
Enter a character:6
Entered character is digit

In (14]: runfile('C:/Users/admin/Desktop/alpha . py',


wdir='C:/Users/admin/Desktop')
Enter a character:&
Entered character is a special character
Write a user defined function in Python named showGrades(S) which takes the
dictionary S as an argument. The dictionary, S contains Name:[Eng,Math,Science] as
key:value pairs. The function displays the corresponding grade obtained by the
students according to the following grading rules :
Average of Eng, Math,Science Grade
=90 A
<90 but >=60 B
<60 C

For example : Consider the following dictionary


S={"AMIT": (92,86,64],"NAGMA": [65,42,43], "DAVID": [92,90, 88] )
The output should be :
AMIT - B
NAGMA - C
DAVID - A

def showGrades (S) :


for K, Vin S. items () :
if sum (V)/3>=90:
Grade="A"
elif sum (V)/3>=60:
Grade="B"
else:
Grade="C"
print (K,"-",Grade)
S={"AMIT" : (92,86,64], "NAGMA": [65,42,431, "DAVID": (92, 90,88]}
showGrades (S)
6

EX.NO: 3
DATE:

CREATING A MENU DRIVEN PROGRAM TO FIND FACTORIAL AND SUM OF LIST OF


NUMBERS USING FUNCTION.

AIM:
To write a menu driven Python Program to find Factorial and sum of list of numbers
using function.
SOURCE CODE:

def Factorial (no) :


F=l
if no<O:
print ("Sorry, we cannot take Factorial for Negative number")
elif no==0:
print ("The Factorial of 0 is 1")
else :
for i in range (1, no+1):
F-F*i
print ("The Factorial of", no, "is :",F)

def Sum List (L) :


Sum=0
for i in range (n) :
Sum=Sum+L [i)
print ("The Sum of List is:",Sum)
# Main Program

print ("1. To Find Factorial")


print ("2. To Find sum of List elements")
opt=int (input ("Enter your choice:"))
if optl:
n=int (input ("Enter a number to find Factorial:"))
Factorial (n)

elif opt=-2:
n=int (input ("Enter how many elements you want to store in List?: "))
for i in range (n) :
ele=int (input (0)
L.append (ele)
Sum List (L)

Result:
Thus, the above Python program has been executed and the output is verified
successfully.

SAMPLE OUTPUT:
Python Executed Program Qutput:
1. To Find Factorial
2. To Find sun of List elements
Enter your choice:1
Enter a number to find Factorial:5
The Factorial of 5 is: 120

You might also like