-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice2.py
More file actions
105 lines (77 loc) · 2.53 KB
/
practice2.py
File metadata and controls
105 lines (77 loc) · 2.53 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Question 1:
# """
# def crazy_about_9(a, b):
# """
# a, b: two integers
# Returns True if either one is 9, or if their sum or difference is 9.
# """
# return a == 9 or b == 9 or a + b == 9 or abs(a - b) == 9
# # When you've completed your function, uncomment the
# # following lines and run this file to test!
# print(crazy_about_9(2, 9))
# print(crazy_about_9(4, 5))
# print(crazy_about_9(3, 8))
# """
# -----------------------------------------------------------------------
# Question 2:
# A year with 366 days is called a leap year. Leap years are necessary to
# keep the calendar synchronized with the sun because the earth revolves
# around the sun once every 365.25 days. Actually, that figure is not
# entirely precise, and for all dates after 1582 the Gregorian correction
# applies. Usually years that are divisible by 4 are leap years, for
# example 1996. However, years that are divisible by 100 (for example,
# 1900) are not leap years, but years that are divisible by 400 are leap
# years (for example, 2000).
# """
# def leap_year(year):
# """
# year(int): a year
# Returns True if year is a leap_year, False if year is not a leap_year.
# """
# if year % 4 != 0 or year % 100 == 0 and year > 1582 and year % 400 != 0:
# return False
# else:
# return True
# # When you've completed your function, uncomment the
# # following lines and run this file to test!
# print(leap_year(1900))
# print(leap_year(2016))
# print(leap_year(2017))
# print(leap_year(2000))
# """
# -----------------------------------------------------------------------
# Question 3:
# Write a function with loops that computes The sum of all squares between
# 1 and n (inclusive).
# """
# def sum_squares(n):
# result = 0
# for x in range(n + 1):
# result += x * x
# return result
# # When you've completed your function, uncomment the
# # following lines and run this file to test!
# print(sum_squares(1))
# print(sum_squares(100))
# age = 20
# if age >= 6:
# print('teenager')
# elif age >= 18:
# print('adult')
# else:
# print('kid')
# iteration = 0
# count = 0
# while iteration < 5:
# # the variable 'letter' in the loop stands for every
# # character, including spaces and commas!
# for letter in "hello, world":
# count += 1
# print("Iteration " + str(iteration) + "; count is: " + str(count))
# iteration += 1
while True:
line = input('> ')
if line == 'done':
break
print(line)
print('Done!')