Simple Calculator:
- Create variables num1 and num2 and assign them numerical values.
- Create variables result_sum, result_diff, result_prod, and result_quotient.
- Perform addition, subtraction, multiplication, and division operations and store the results in the corresponding variables.
- Print the results.
Temperature Conversion:
- Create a variable temperature_celsius and assign a temperature in Celsius.
- Convert it to Fahrenheit using the formula: F = (C * 9/5) + 32.
- Print the result.
Conditional Statements
Age Verification:
- Ask the user to input their age.
- Use logical operators to check if the age is between 18 and 65.
- Print whether the user is of working age or not.
Comparison:
- Create two variables, x and y, with numerical values.
- Use comparison operators to check if x is greater than, less than, equal to, not equal to, etc., y.
- Print the results.
Calculate Area:
- Ask the user to input the radius of a circle.
- Calculate and print the area of the circle using the formula: area = π * r^2.
Number Categorization:
- Ask the user to input a number.
- Use if, elif, and else statements to categorize the number as positive, negative, or zero.
- Print an appropriate message.
Grade Calculator:
- Ask the user to input their score on an exam (out of 100).
- Use if, elif, and else statements to assign a letter grade (A, B, C, D, F).
- Add an additional category for scores above 100 (Extraordinary) and below 0 (Invalid).
Greetings Based on Time:
- Write a program that asks the user to input the current hour (in 24-hour format).
- Use if, elif, and else statements to print a different greeting based on the time of day (morning, afternoon, evening).
Logical Operators
Age Eligibility:
- Ask the user to input their age.
- Use logical operators to check if the age is between 18 and 25 or if it’s above 65.
- Print a message indicating whether the person is eligible for a youth discount or a senior discount.
Membership Discount:
- Ask the user if they are a premium member (yes/no).
- Ask for the total purchase amount.
- Use logical operators to apply a discount of 20% if they are a premium member and the purchase amount is greater than $50.
- Print the final amount after applying the discount.
Weather Recommendation:
- Ask the user for the current temperature and whether it’s raining (yes/no).
- Use logical operators to provide a weather recommendation:
- If the temperature is above 30°C and it’s not raining, recommend going to the beach.
- If temperature is between 20°C and 30°C, recommend a picnic.
- If the temperature is below 20°C or it’s raining, recommend staying indoors.
Voting Eligibility:
- Ask the user to input their age and citizenship status (yes/no for citizen).
- Use logical operators to determine if the person is eligible to vote.
- Print a message indicating whether the person is eligible to vote or not.
Looping Statements
Print Even Numbers:
- Use a for loop to print all even numbers between 1 and 20.
Odd Number Skip:
- Use a loop to print numbers from 1 to 10, but skip odd numbers
Number Search:
- Use a loop to search for a specific number in a list. If found, print a message and break out of the loop.
Factorial Calculator:
- Ask the user to input a number.
- Use a for loop to calculate and print the factorial of that number.
Prime Number Checker:
- Ask the user to input a number.
- Use a loop to check if the number is a prime number.
- Print a message indicating whether the number is prime or not.
Fibonacci Sequence:
- Generate and print the first 20 numbers in the Fibonacci sequence using a loop.
Number Guessing Game:
- Generate a random number between 1 and 100.
- Allow the user to guess the number within a limited number of attempts.
- Provide feedback on whether the guess is too high, too low, or correct.
- Use a loop to continue the game until the user guesses correctly or reaches the maximum number of attempts.