-
-
Save barnash/7314104 to your computer and use it in GitHub Desktop.
Code samples from Recitation2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| m = int(input("enter a positive integer to check if it's a**2 + b**2: ")) | |
| for a in range(1, m): | |
| for b in range(1 ,m): | |
| if a**2 + b**2 == m: | |
| print (a, b, m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n = int(input("enter a positive integer to check if it's a**2 + b**2: ")) | |
| for m in range(1, n): | |
| for a in range(1, m): | |
| for b in range(1 ,m): | |
| if a**2 + b**2 == m: | |
| print (a, b, m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def check_number(m): | |
| for a in range(1, m): | |
| for b in range(1 ,m): | |
| if a**2 + b**2 == m: | |
| print (a, b, m) | |
| n = int(input("enter a positive integer to check if it's a**2 + b**2: ")) | |
| for m in range(1, n): | |
| check_number(m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| count = int(input("How many grades?")) | |
| s = 0 | |
| above = 0 | |
| grades = [] | |
| for i in range(count): | |
| grade = float(input("enter your grade: ")) | |
| grades = grades + [grade] | |
| s = s + grade | |
| # s = sum(grades) #instead of counting inside the loop | |
| avg = s / count | |
| for gr in grades: | |
| if gr > avg: | |
| above = above + 1 | |
| print(above, "grades are above the average", avg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment