first hw batch 15.3.25 at 11:09
This commit is contained in:
commit
288c7e127a
10 changed files with 73 additions and 0 deletions
BIN
py/BasicIfStatements/BasicIfStatements.pdf
Normal file
BIN
py/BasicIfStatements/BasicIfStatements.pdf
Normal file
Binary file not shown.
8
py/BasicIfStatements/challenge1.py
Normal file
8
py/BasicIfStatements/challenge1.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Ask the user for their age
|
||||||
|
age = int(input("Enter your age: "))
|
||||||
|
|
||||||
|
# Check if the user is 18 or older
|
||||||
|
if age >= 18:
|
||||||
|
print("You can vote")
|
||||||
|
else:
|
||||||
|
print("You cannot vote yet")
|
10
py/BasicIfStatements/challenge2.py
Normal file
10
py/BasicIfStatements/challenge2.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Question: Ask the user to enter a password. If they enter “letmein”, display the message “access granted”.
|
||||||
|
|
||||||
|
# Ask the user to enter the password
|
||||||
|
password = input("Enter your password: ").strip()
|
||||||
|
|
||||||
|
# Check if the password is "letmein"
|
||||||
|
if password == "letmein":
|
||||||
|
print("Access granted")
|
||||||
|
else:
|
||||||
|
print("Access denied")
|
12
py/BasicIfStatements/challenge3.py
Normal file
12
py/BasicIfStatements/challenge3.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# Start of the program
|
||||||
|
num = int(input("Enter a number: "))
|
||||||
|
|
||||||
|
# Check if the number is greater than 100
|
||||||
|
if num > 100:
|
||||||
|
print("Thank you")
|
||||||
|
else:
|
||||||
|
num += 100
|
||||||
|
print("I have changed your number as it was too low")
|
||||||
|
|
||||||
|
# Output the final number
|
||||||
|
print("Your number is", num)
|
BIN
py/IfElseStatements/IfElseStatements.pdf
Normal file
BIN
py/IfElseStatements/IfElseStatements.pdf
Normal file
Binary file not shown.
10
py/IfElseStatements/challenge1.py
Normal file
10
py/IfElseStatements/challenge1.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Question: Ask if the user likes pizza. If they answer “yes” display “I like pizza too”, otherwise display “My favourite food is pizza.”
|
||||||
|
|
||||||
|
# Ask the user if they like pizza
|
||||||
|
response = input("Do you like pizza? (yes/no): ").strip().lower()
|
||||||
|
|
||||||
|
# Check the response and display appropriate message
|
||||||
|
if response == "yes":
|
||||||
|
print("I like pizza too!")
|
||||||
|
else:
|
||||||
|
print("My favourite food is pizza.")
|
10
py/IfElseStatements/challenge2.py
Normal file
10
py/IfElseStatements/challenge2.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Question: Change your password program you created earlier. If they enter “letmein”, display the message “access granted” otherwise display “access denied”.
|
||||||
|
|
||||||
|
# Ask the user to enter the password
|
||||||
|
password = input("Enter your password: ").strip()
|
||||||
|
|
||||||
|
# Check if the password is "letmein"
|
||||||
|
if password == "letmein":
|
||||||
|
print("Access granted")
|
||||||
|
else:
|
||||||
|
print("Access denied")
|
0
py/IfElseStatements/challenge3.py
Normal file
0
py/IfElseStatements/challenge3.py
Normal file
10
py/basicifstatements/challenge1.py
Normal file
10
py/basicifstatements/challenge1.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Question: Ask the user for their age. If they are 18 or older tell them “You can vote”.
|
||||||
|
|
||||||
|
# Ask the user for their age
|
||||||
|
age = int(input("Enter your age: "))
|
||||||
|
|
||||||
|
# Check if the user is 18 or older
|
||||||
|
if age >= 18:
|
||||||
|
print("You can vote")
|
||||||
|
else:
|
||||||
|
print("You cannot vote yet")
|
13
py/ifelsestatements/challenge3.py
Normal file
13
py/ifelsestatements/challenge3.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Ask the user to input two numbers
|
||||||
|
num1 = float(input("Enter the first number: "))
|
||||||
|
num2 = float(input("Enter the second number: "))
|
||||||
|
|
||||||
|
# Calculate the average
|
||||||
|
answer = (num1 + num2) / 2
|
||||||
|
|
||||||
|
# Check if the average is less than 100
|
||||||
|
if answer < 100:
|
||||||
|
print("The average is", answer)
|
||||||
|
|
||||||
|
# Print "Goodbye" at the end
|
||||||
|
print("Goodbye")
|
Loading…
Add table
Reference in a new issue