0% found this document useful (0 votes)
0 views5 pages

Anishka Python

This document contains a series of Python programming exercises aimed at beginners. Each exercise includes a specific task, such as converting temperatures, checking if a number is odd or even, and calculating factorials, along with the corresponding Python code. The programs are designed to help users practice basic programming concepts and syntax in Python.

Uploaded by

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

Anishka Python

This document contains a series of Python programming exercises aimed at beginners. Each exercise includes a specific task, such as converting temperatures, checking if a number is odd or even, and calculating factorials, along with the corresponding Python code. The programs are designed to help users practice basic programming concepts and syntax in Python.

Uploaded by

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

PYTHON PROGRAMS AI WORKSHEET

Anishka Chopra IX-C

1 Python program that takes input of temperature in Celsius and converts

temperature from Celsius to Fahrenheit.

# Python program to convert Celsius to Fahrenheit

# Get the temperature in Celsius from the user

celsius = float(input("Enter temperature in Celsius: "))

# Convert Celsius to Fahrenheit

fahrenheit = (celsius * 9/5) + 32

# Print the result

print(f"{celsius} degrees Celsius is equal to {fahrenheit} degrees Fahrenheit")

2. Write a Python program that takes input in minutes and converts minutes into seconds.

The program should perform the conversion, and print the result.

# Python program to convert minutes to seconds

# Get the time in minutes from the user

minutes = int(input("Enter time in minutes: "))

# Convert minutes to seconds

seconds = minutes * 60

# Print the result


print(f"{minutes} minutes is equal to {seconds} seconds")

3. Write a Python program that takes a number as input from the user and prints whether it

is odd or even.

# Python program to check if a number is odd or even

# Get the number from the user

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

# Check if the number is odd or even

if num % 2 == 0:

print(f"{num} is even")

else:

print(f"{num} is odd")

4. Write a Python program that checks if a given year is a leap year or not. HINT- A leap

year is either: Divisible by 4 but not divisible by 100, or Divisible by 400.

# Python program to check if a year is a leap year

# Get the year from the user

year = int(input("Enter a year: "))

# Check if the year is a leap year

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

print(f"{year} is a leap year")

else:

print(f"{year} is not a leap year")

5. Write a Python program that takes three numbers as input from the user and prints the
largest among them.

# Python program to find the largest of three numbers

# Get the three numbers from the user

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

num2 = float(input("Enter the second number: "))

num3 = float(input("Enter the third number: "))

# Find the largest number

if num1 >= num2 and num1 >= num3:

largest = num1

elif num2 >= num1 and num2 >= num3:

largest = num2

else:

largest = num3

# Print the largest number

print(f"The largest number is {largest}")

6. Write a Python program that checks if a person is eligible to vote or not. HINT- Age

>=18 are eligible to vote.

# Python program to check if a person is eligible to vote

# Get the person's age from the user

age = int(input("Enter your age: "))

# Check if the person is eligible to vote

if age >= 18:

print("You are eligible to vote.")


else:

print("You are not eligible to vote.")

7. Write a Python program that uses a for loop to print even numbers and odd numbers from

20 to 40.

# Python program to print even and odd numbers from 20 to 40

print("Even numbers from 20 to 40:")

for i in range(20, 41):

if i % 2 == 0:

print(i)

print("\nOdd numbers from 20 to 40:")

for i in range(20, 41):

if i % 2 != 0:

print(i)

8. Write a Python program that takes a number as input from the user and prints its

multiplication table.

# Python program to print the multiplication table of a given number

# Get the number from the user

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

# Print the multiplication table

print("Multiplication table of", num, ":")

for i in range(1, 11):

print(f"{num} x {i} = {num * i}")


9. Write a Python program that calculates the factorial of a number entered by the user.

# Python program to calculate the factorial of a number

# Get the number from the user

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

# Calculate the factorial

factorial = 1

for i in range(1, num + 1):

factorial *= i

# Print the result

print(f"The factorial of {num} is {factorial}")

10. Write a Python program that print sum of first n numbers. Input n from user.

# Python program to calculate the sum of the first n numbers

# Get the number from the user

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

# Calculate the sum

sum_of_first_n = sum(range(1, n + 1))

# Print the result

print(f"The sum of the first {n} numbers is {sum_of_first_n}")

You might also like