Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
python_study_note_for loop@nested loop
### question 1 def square(n): return n*n def sum_squares(x): sum = 0 total = 0 for sum in range(x): total += square(sum) sum += 1 return total print(sum_squares(10)) ### question 2 values = [23, 52, 59, 37, 48] sum = 0 length = 0 for value in values: sum += value length += 1 print("Total sum: " + str(sum) + " - Average: " + str(sum/length)) ### question 3 product = 1 for n in range(1, 10): product = product * n print(product) ### question 4 for x in range(0, 101, 10): print(x) ### question 5 for left in range(7): for right in range(left, 7): print("[" + str(left) + "|" + str(right) + "]", end=" ") print() ### question 6 teams = ['Dragon', 'Wolves', 'Pandas', 'Unicorns'] for home_team in teams: for away_team in teams: if home_team != away_team: print(home_team + " vs " + away_team)
run
|
edit
|
history
|
help
0
Python
exception handling from user
https://rextester.com/HYVN80193
Skillenza Common subjects
Fibonacci to the Nth number
ReverseArray.py
innerclass.py
montecarlo
PyRegSearch
Add missing person