0% found this document useful (0 votes)
6 views3 pages

Ai Python Project3

Uploaded by

parnikapb104
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)
6 views3 pages

Ai Python Project3

Uploaded by

parnikapb104
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/ 3

PYTHON AI PROJECT

1) Write a Program to print out the name giver by the user as input.

x = input ("Enter A Name of


person: ")

print(x)

2) Check whether a number is even or odd.


x = int (input ("Enter a Number: "))

if x%2 == 0:
print ("The Number is Even")
else:
print ("The number is Odd")

3) Check if a certain year is a leap year or not.

year = int(input('Enter year : '))

if (year%4 == 0 and year%100 != 0) or


(year%400 == 0) :
print(year, "is a leap year.")
else :
print(year, "is not a leap year.")

4) Write a program to find the largest number among the three input numbers

num1 = float (input("Enter first number: "))


num2 = float (input("Enter second number: ")
num3 = float (input("Enter third number: "))

if (num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2

5) Check whether the number entered is prime or not


num = int(input("Enter a number: "))

if num > 1:
else:
for i in range(2, int(num/2)+1):
largest = num3
if (num % i) == 0:
print(num, "is not a prime number")
print("The largest
break number is", largest)
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")
6) Find the factorial of a number provided by the user
num = int(input("Enter a number: "))

factorial = 1

if num < 0:
print("Sorry, factorial does not exist for
negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)

7) Display the multiplication table of a number entered by the user


num = int(input("Display multiplication table of: "))

for i in range(1, 11):


print(num, 'x', i, '=', num*i)

8) Display the Fibonacci sequence upto nth , where the user provides the value of n
n = int(input("How many terms? "))

n1, n2 = 0, 1
count = 0

if n <= 0:
print("Please enter a positive integer")
elif n == 1:
print("Fibonacci sequence upto",n,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < n:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1

9) Check whether the number entered is an Armstrong number


number = int(input("Enter a number: "))
digits = len(str(number))
temp = number
add_sum = 0
while temp != 0:
k = temp % 10
add_sum += k**digits
temp = temp//10
if add_sum == number:
print('Given number is an Armstrong Number')
else:
print('Given number is not a Armstrong Number')
10) Find the sum of natural numbers upto n, where user enters n

num = int(input("Enter the number till where you


want the sum: "))

if num < 0:
print("Enter a positive number")
else:
sum = 0
while(num > 0):
sum += num
num -= 1
print("The sum is", sum)

11) Write a program to find the length of a string entered by the user

a = input("Enter a string: ")


print(len(a))

12) Write a program to find the sum of digits of a number


n = [int(d) for d in input("Enter the number : ")]
print("the sum of digits is : ", sum(n))

13) Check whether the person is eligible to cast a vote


age = int(input("Enter age of a user: "))

if age >= 18:


print("User is eligible for voting: ")
else:
print("User is not eligible for voting: ")

14) Create a list of five elements where the user enters the value of each element. Print the list created and also the reverse order of that list
i = 5;

a=[]

while i>0:
print("Enter number: ")
num = input()
a.append(num)
i= i-1
print(a)
a.reverse()
print(a)

15) Ask the user to provide the integer inputs to make a list. Store only the even values given and print the list

list1 = [12, 19, 28, 37, 69, 98]

for num in list1:

if num % 2 == 0:
print(num, end=" ")

You might also like