shreya gaur python 50 projects
shreya gaur python 50 projects
PROJECTS:
1. Sum of two numbers: Description: Write a program
that takes a number as input and outputs the sum
of its dig
Logic building:
-Ask the User for Two Numbers (num1 , num2)
-Perform the Addition
Now that we have two numbers (num1 and num2), we
can simply add them using
num1 + num2.
-Display the Result.
print(num1,"+",num2,"=",num1+num2)
Algorithm building:
- Start
- Ask the user to enter the first number
-Ask the user to enter the second number
-Perform addition
Compute sum = num1 + num2
- Display the result
PYTHON CODE:
Code-
Output:
x------------------------------------------------x
2. Multiplication Table Generator: Description: Write a
program to display the multiplication table of a
given number.
Logic building:
-Input Collection:
Ask the user to enter a number (variable= num) for which they want
the multiplication table.
Ask the user to enter the range (variable= r) up to which the table
should be generated.
- Loop through the Range:
Use a for loop to iterate from 1 to r.
In each iteration, multiply num by the current value of i and print the
result in a formatted way.
- Output Display
ALGORITHM BUILDING:
- Start
- make user enter the number for which they want to generate
the multiplication table.
- make user to enter the range (r) for the table.
- Use a loop (for i in range (1, r+1)) to iterate from 1 to r:
Multiply num by i.
- Print the result in the format: num x i = result.
- End.
PYTHON CODE:
Code-
Output-
x--------------------------------------
x
3. Find the Largest Number: Description: Write a
program to find the largest of three numbers
entered by the user.
Logic building:
-Input Collection:
Ask the user to enter three numbers (variable= num1 ,
num2 , num3) for which they want the comparison in
between.
- Use conditional to compare the number:
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
- Output Display
Algorithm building:
-Start
-take input of three numbers
-Use conditional to compare the number.
-print Output
-End.
PYTHON CODE:
Code-
Output-
x--------------------------------------x
LOGIC BUILDING:
- here is string reversal and comparison.
- Strings in Python can be easily reversed using slicing
([::-1]).
- By comparing the original and reversed versions, we
determine if the word reads the same forward and
backward.
ALGORITHM BUILDING:
1. Input the Word
Take a string input from the user.
2. Reverse the String
Use slicing ([::-1]) to reverse the string.
3. Compare the Original and Reversed Strings
If both are the same, it's a palindrome.
Otherwise, it's not.
4. Display the Result
Print whether the input is a palindrome or not.
PYTHON CODE:
Code-
Output-
x---------------------------------------x
LOGIC BUILDING:
Definition of Prime Number: A prime number is a natural
number greater than 1 that has no divisors other than 1
and itself.
Looping Mechanism: The loop runs from 2 to n-1 to
check divisibility.
We are going higher than n cause a number cant be fully
divisible by a number greater than it.
ALGORITHM BUILDING:
Input the Number
-Take an integer input from the user.
Check for Prime Conditions
-If the number is less than 2, return False (not
prime).
-Loop from 2 to n-1 and check if n is divisible by any
number in this range.
-If a divisor is found, return False (not prime).
-If no divisors are found, return True (prime).
Display the Result
-If the function returns True, print "It's a prime
number!"
-Otherwise, print "It's not a prime number."
PYTHON CODE-
Code-
Output-
x-------------------------------x
6. Even or Odd Checker: Description: Create a program
that checks if a given number is even or odd.
LOGIC BUILDING:
Definition of Even and Odd:
A number is even if it is divisible by 2 , i.e.,
remainder 0 when divided by 2.
A number is odd if it is not divisible by 2 , i.e.,
remainder 1 when divided by 2.
ALGORITHM BUILDING:
Input the Number
-Take a number as input from the user.
Check Even or Odd Condition
-If the number is divisible by 2 (number % 2 ==
0), it is even.
-Otherwise, it is odd.
Display the Result
-Print "It is even." if the number is even.
-Print "It is odd." if the number is odd.
PYTHON CODE:
Code-
Output-
x-------------------------------------------------------------x
7. Simple Calculator: Description: Create a calculator
that performs basic arithmetic operations like
addition, subtraction, multiplication, and division.
LOGIC BUILDING:
String Matching for User Input
The code checks if the entered operation is in a
predefined list ('add', 'sub', 'mul', 'div').
If the user enters an invalid operation, it prints
"Invalid input".
Basic Arithmetic Operations
The program performs different mathematical
operations based on user input.
It prints the operation
ALGORITHM BUILDING:
Take User Input
Ask the user to enter their choice of operation (add,
sub, mul, div).
Validate the Input
Check if the user's choice is one of the valid
operations (add, sub, mul, div).
If the input is invalid, print "Invalid input" and exit.
Take Two Numbers as Input
Ask the user to enter two numbers.
Convert the inputs to float for decimal number
support.
Perform the Operation Based on User Choice
If the choice is "add", perform addition (num1 +
num2).
If the choice is "sub", perform subtraction (num1 -
num2).
If the choice is "mul", perform multiplication (num1
* num2).
If the choice is "div", perform division (num1 /
num2).
Display the Result
Print the result of the selected operation.
PYTHON CODE:
Code-
Output-
x---------------------------------x
8. Number Guessing Game: Description: The computer randomly selects a
number, and the player has to guess it. The game gives feedback on
whether the guess is too high or too low until the user guesses correctly.
LOGIC BUILDING:
1. Random Number Generation:
The program use random module to select a number
randomly within a given range.
2. User Input:
The user inputs a number through input(), which is then
converted to an integer.
If the user enters an invalid input (e.g., letters), handle
it with a try-except block to prevent crashes.
3. Conditional:
number is compared with the secret number:
If smaller, print "Too low!"
If greater, print "Too high!"
If equal, print success message and break the loop.
4. Loop:
while True loop keeps running until the correct number
is guessed.
The loop ensures that the game doesn’t stop until the
user wins.
ALGORITHM BUILDING:
-Start
-Generate a Random Number
-Initialize attempts = 0
-Repeat until the correct guess:
- Take user input
- If input is invalid, ask again
- Compare input with secret number
- If too low, print "Too low!"
- If too high, print "Too high!"
- If correct, print success message and exit
- Increment attempt count
-End Game
PYTHON CODE:
Code-
Output-
x-----------------------------x
9. Simple Interest Calculator: Description: Write a
program that calculates the simple interest based
on principal, rate of interest, and time.
LOGIC BUILDING:
- Use input() to get user values and convert them to
float for accurate calculations.
- Use basic arithmetic operations for interest
calculation.
-Print the result using formatted output.
ALGORITHM BUILDING:
-Take Inputs from user
principal amount
rate of interest
time period
-Calculate Simple Interest
Use the formula:
where:
o P is the principal amount
o R is the rate of interest
o T is the time period
-Display the Result
Print the simple interest.
PYTHON CODE:
Code-
Output-
x-----------------------------------------x
10. Fibonacci Sequence Generator: Description:
Write a program to generate the Fibonacci sequence
up to a certain number of terms.
LOGIC BUILDING:
ALGORITHM BUILDING:
1. Take Input
user enter the number of terms (nterms).
2. Check for Valid Input
If nterms is less than or equal to 0, print an
error message.
If nterms is equal to 1, print only the first
Fibonacci number (0).
3. Initialize Variables
Set n1 = 0 and n2 = 1 (the first two numbers of
the Fibonacci sequence).
Initialize a count = 0 to keep track of the
number of terms printed.
4. Generate Fibonacci Sequence
Use a while loop to generate numbers up to
nterms.
Print the current Fibonacci number (n1).
Compute the next number using nth = n1 + n2.
Update n1 and n2 for the next iteration.
5. End the Loop when Required Terms are Generated
The loop continues until count == nterms.
PYTHON CODE:
Code-
Output-
x-------------------------------------x