-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonCode.py
More file actions
61 lines (57 loc) · 1.73 KB
/
PythonCode.py
File metadata and controls
61 lines (57 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name = input("Your name : ")
while len(name) < 3:
print("Name must at least 3 char")
name = input("Your name : ")
while len(name) > 50:
print("Name must less 50 char")
name = input("Your name : ")
color = input("Favourite color : ")
print(name, "Likes", color)
print('*' * 10)
# Type conversion
birth_year = input("Birth Year : ")
print(type(birth_year))
age = 2020 - int(birth_year) # Conversion
print(type(age))
print(age)
# Mortgage Calculation
house_price = 1000000
is_good_credit = True
has_high_income = False
has_criminal_record = False
down_payment = 0
if is_good_credit or has_high_income and not has_criminal_record:
down_payment = house_price * .1
else:
down_payment = house_price * .2
print(f"Down payment: ${down_payment}")
print("Python Error Handling ".upper())
age = -1
while age <= 0:
try:
age = int(input('enter your age in years: '))
if age < 0:
print('your age must be positive')
except ZeroDivisionError:
print("Age cannot be Zero :")
except(ValueError, EOFError):
print('invalid response')
print('Welcome to the GPA calculator.')
print('Please enter all your letter grades, one per line.')
print('Enter a blank line to designate the end.')
points = {'A+': 4.0, 'A': 4.0, 'A-': 3.67, 'B+': 3.33, 'B': 3.0, 'B-': 2.67,
'C+': 2.33, 'C': 2.0, 'C': 1.67, 'D+': 1.33, 'D': 1.0, 'F': 0.0}
num_courses = 0
total_points = 0
done = False
while not done:
grade = input()
if grade == '':
done = True
elif grade not in points:
print("Unknown grade '{0}' being being ignored")
else:
num_courses += 1
total_points += points[grade]
if num_courses > 0:
print('Your GPA is {0:.3}'.format(total_points / num_courses))