Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions projects/001-taxi-fare/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'''
In a particular jurisdiction, taxi fares consist of:
- base fare of €4.00,
- plus €0.25 for every 140 meters travelled.

Write a function named **taxi fare** that takes the distance travelled (in kilometers) as its only parameter
and returns the total fare as its only result.
Write a main program that demonstrates the function.
'''

def taxi_fare(kilometers):
addedtaxes = kilometers // 140
taxfare = 0.25 * addedtaxes
totalfare = 4.00 + taxfare
return totalfare

kilometers = int(input("Kilometers: "))
totalfare = taxi_fare(kilometers)
print("Total fare = ", totalfare)
13 changes: 13 additions & 0 deletions projects/002-shipping-calculator/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'''
An online retailer provides express shipping for many of its items at a rate of:
- €10.99 for the first item in an order
- €2.99 for each subsequent item in the same order.

Write a function named **shipping calculator** that takes the number of items in the order as its **only parameter**.

Return the shipping charge for the order as the function’s result.

Include a main program that reads the number of items purchased from the user
and displays the shipping charge.
'''

34 changes: 34 additions & 0 deletions projects/009-password-validation/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'''
In this exercise you will write a function named is valid password
that determines whether a password is good.
We will define a good password to be a one that is:

at least 8 characters long
contains at least one uppercase letter
contains at least one lowercase letter
contains at least one number
Your function should return True if the password passed to it as its
only parameter is good.
Otherwise it should return False.

Include a main program that reads a password from the user and reports
whether it is good.
Ensure that your main program only runs when your solution has not
been imported into another file.
'''

def valid_password(userpassword, uppercase, lowercase, numbers):
if len(userpassword) >= 8 and uppercase in userpassword and lowercase in userpassword and numbers in userpassword:
return True
else:
return False

userpassword = input("Please enter a password: ")
uppercase = "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
lowercase = "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"
numbers = "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
passwordcheck = valid_password(userpassword, uppercase, lowercase, numbers)
if passwordcheck == True:
print("The password inserted is correct!")
else:
print("The password inserted is WRONG!\nIt needs to contain at least one uppercase letter, at least one lowercase letter, at least one number and it should be at least 8 characters long!")