Skip to content

Commit 23db83d

Browse files
committed
init
1 parent e74b618 commit 23db83d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+295
-0
lines changed

birthyear.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
birth_year = input('Birth year: ')
2+
print(type(birth_year))
3+
age = 2022 - int(birth_year)
4+
print(type(age))
5+
print(age)

bmicalculator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Coding a simple Python BMI calculator
2+
3+
# Receive input from the user
4+
weight=float(input("Enter your weight in kilograms:"))
5+
height=float(input("Enter your height in centimeters:"))
6+
7+
# Calculate the BMI
8+
bmi=weight/((height/100)*(height/100))
9+
10+
# Display the result to the user
11+
print("Your Body Mass Index (BMI) is:",round(bmi,2))

cargame.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
command = ""
2+
started = False
3+
4+
while True:
5+
command = input("> ").lower()
6+
if command == "start":
7+
if started:
8+
print("Car is already started!")
9+
else:
10+
started = True
11+
print("Car started")
12+
elif command == "stop":
13+
if not started:
14+
print("Car is already stopped")
15+
else:
16+
started = False
17+
print("Car stopped")
18+
elif command == "help":
19+
print("""
20+
start - to start the car
21+
stop - to stop the car
22+
quit - to quit""")
23+
elif command == "quit":
24+
break
25+
else:
26+
print("Sorry, I don't understand that")
27+

comparison.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
temperature = 25
2+
3+
if temperature > 30:
4+
print("It's a hot day")
5+
print("Drink plenty of water")
6+
elif temperature > 20:
7+
print("It's a nice day")
8+
print("Done")

comparison2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name = input("Enter your name: ")
2+
3+
if len(name) < 3:
4+
print("Name must be at least 3 characters")
5+
elif len(name) > 50:
6+
print("Name must be a maximum of 50 characters")
7+
else:
8+
print("Name looks good!")

conversion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
birth_year = input("Enter your birth year: ")
2+
age = 2022 - int(birth_year)
3+
print(age)

costcart.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
prices = [10, 20, 30]
2+
3+
total = 0
4+
for price in prices:
5+
total += price
6+
print(f"Total: {total}")

forloop.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
numbers = [1, 2, 3, 4, 5]
2+
for item in numbers:
3+
print(item)
4+
5+
i = 0
6+
while i < len(numbers):
7+
print(numbers[i])
8+
i = i + 1

formattedstring.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
first = 'John'
2+
last = 'Smith'
3+
message = first + ' [' + last + '] is a coder'
4+
msg = f'{first} [{last}] is a coder'
5+
print(message)
6+
print(msg)

functions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def function1():
2+
print("ah")
3+
print("ah2")
4+
print("this is outside the function")
5+
function1()
6+
7+
def function2(x):
8+
return 2*x
9+
a = function2(3)
10+
b = function2(4)
11+
c = function2(5)
12+
print(b)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy