Info Tech
Info Tech Review
Variables and Types
Problem: Define variables to store the length and width of a rectangle. Calculate and print its area and perimeter.
length = 10
width = 5
# Calculate area and perimeter
area=length*width
perimeter=2(length+width)
print(area)
print(perimeter)
Using Input
Problem: Write a program to ask the user for the radius of a circle and calculate its area and circumference.
# Get radius from user (make sure to convert to floating point)
radius=float(input(“Radius:”)
# Calculate area and circumference
area=3.14*r**2
Booleans, If Statements, and Comparison Operators
Problem: Determine whether a number is even or odd using an if statement.
python
# Get integer from user
num = int(input("Enter a number: "))
# Check if the number is even or odd
If number%2:
print(str(num)+”is an even number”)
Else:
print(str(num)+”is an odd number”)
Logical Operators
Problem: Write a program to check if a given year is a leap year. A year is a leap year if:
It is divisible by 4 but not by 100, OR
It is divisible by 400.
#Get year from user
year = int(input("Enter a year: "))
# Determine if the year is a leap year and state so.
if year % 4 == 0:
if year % 100 == 0: # If also divisible by 100
return year % 400 == 0 # Check if divisible by 400
else:
return True # If not divisible by 100, it's a leap year
Else:
return False
Floating Point Numbers and Rounding
Problem: Calculate the tip amount for a restaurant bill. Ask the user for the bill total and the tip percentage. Round the result to 2 decimal places.
# Get bill total from user
bill = float(input("Enter the bill total: "))
tip_percentage = float(input("Enter the tip percentage (10-15%): "))
# Calculate and round tip
# Print the final bill total including the tip
For Loops
Problem: Print the first 10 square numbers using a for loop.
# Write code below:
For i in range
While Loops and Breaks
Problem: Write a program that keeps asking the user to guess a secret number until they guess it correctly. The secret number is 7. Hint: You may need to use a break statement if the user guess correctly
secret_number = 7
while True:
# Write code below
Functions and Return Values
Problem: Write a function to calculate the factorial of a number. Test the function with an example.
N! =N*(N-1)*(N-2)*...*2*1
Example 4! =4*3*2*1
def factorial(n):
# Calculate factorial
print(factorial(5)) # Example usage
Functions and Return Values
Problem: Write a function that converts an input in degrees celsius to fahrenheit
def cel_to_fahr(c):
# Convert input c to fahrenheit. Write code below
Functions and Return Values
Problem: Write a function that finds a given percentage of a number
Example 20% of 200 is 0.2*200= 40
def percent_of_number(percent,number):
# Write code below
#Make sure to convert percent to decimal first
Functions and Return Values
Problem: Write a function that calculates the amount of an investment with compound interest after t years.
def amount(p,r, n,t):
# Write code below
#Make sure to convert rate to decimal first
Strings, Indexing, and Slicing
Problem: Ask the user for a word and print the first and last characters of the word. Also, print the word in reverse.
word = input("Enter a word: ")
# Extract and print characters
Lists and List Methods
Problem: Create a list of integers. Add a number to the list, remove a number, and sort the list.
python
Copy code
numbers = [3, 1, 4, 1, 5]
# Perform operations
For Loops and Lists
Problem: Write a program to calculate the average of a list of numbers.
python
numbers = [30, 50, 70, 90, 110]
# Calculate average
15. List Comprehension
Problem: Create a list called cubes of the first 10 cube numbers using list comprehension.
1^3= 1 2^3= 8 , 3^3= 27 etc
16. List Comprehension
Problem: Given the list below in miles, convert to km using list comprehension
distance_miles=[100, 250, 145, 170, 95, 62]
# Write code below, call the list distance_km
17. Dictionaries
Problem: Create a dictionary to store the names Alice, Bob and Charlie and their test scores.
Alice got a 92, Bob got a 78 and Charlie got 85
# Call the dictionary students
# Get their scores and calculate the average
Flashcards are a learning tool used to aid in memorization and study. They typically consist of a card with a prompt or question on one side and the answer or definition on the other. Flashcards are effective for learning vocabulary, concepts, and facts across various subjects. They can be used for self-testing, spaced repetition, and active recall, making them a popular choice for students of all ages.