0% found this document useful (0 votes)
18 views11 pages

Assignment 2

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)
18 views11 pages

Assignment 2

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/ 11

Assignment – 2

Name: -Syandilya Sai Vardhan


Roll no: -21BCE9037
Conditional Statements in python
Grade Calculator:
1. Write a python program that takes a student’s score as
input and prints their corresponding grade. Assume the
grading scale is A(90-100), B(80-89), C(70-79),D(60-69),

and F(0-59).

Sol: -
Leap Year Checker:
Create a python program that checks if a given year is a leap
year. A leap year is divisible by 4, except for years that are
divisible by 100 but not divisible by 400.
Sol: -

Positive/Negative/Zero Checker
Write a python program that takes a number as input and prints
whether it’s positive, negative, or zero.
Sol: -
Largest of three number:
Develop a python program that takes three number as input and
prints the largest among them.

Sol: -
Temperature Converter:
Creative a python program that converts temperature
between Celsius and Fahrenheit. The user should be able to
input a temperature and its unit, and the program should
output the converted temperature.
Sol: -
Looping
Print Even Number
Write a python program to print all even numbers from 1 to
20 using a for loop
Factorial Calculator:
Develop a python program that calculates the factorial of a
given number using a while loop. The factorial of a non-
integer n is the product of all positive integers less than or
equal to n.
Sol: -

Pattern printing -Square:


Create a python program that prints a square pattern of ‘*’
characters with a side length specified by the user using for loop.
Sol: -
Number Guessing Game:
Implement a simple number guessing game in python. Generate a
random number between 1 and 100 and ask the user to guess the
number. Provide hints (higher/lower) and continue the game until
the user guesses correctly using a while loop
Print Fibonacci series:
Write a python program to print the Fibonacci series up to a specified
number of terms using a for loop. The Fibonacci series is a sequence where
each number is the sum of the two preceding ones, starting with 0 and 1.
Sol: -

Exception Handling
11. Safe Division:
Write a Python program that takes two numbers as input
and performs division. Handle the ZeroDivisionError by
displaying a message indicating that division by zero is not
allowed.
12. File Reader with Exception Handling:
Create a Python program that reads content from a user-
specified file. Handle the FileNotFoundError by displaying a
message if the file is not found.
13. Input Validation with a Loop:
Implement a program that asks the user to input a positive
integer. Use a loop and exception handling to ensure that
the user enters a valid positive integer.
14. Dictionary Access with Exception Handling:
Write a Python program that accesses a key in a dictionary.
Handle the KeyError by displaying a message if the key is
not present in the dictionary.

15. Custom Exception:


Define a custom exception class called NegativeValueError.
Write a Python program that takes a number as input and
raises this
exception if the number is negative.

You might also like