Advertisement
veronikaaa86

While Loop - Python

Feb 5th, 2022 (edited)
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. 01. Read Text
  2.  
  3. line = input()
  4.  
  5. while line != "Stop":
  6. print(line)
  7. line = input()
  8.  
  9. ==========================================
  10. 02. Password
  11.  
  12. username = input()
  13. reg_pass = input()
  14.  
  15. current_pass = input()
  16. while current_pass != reg_pass:
  17. current_pass = input()
  18.  
  19. print("Welcome " + username + "!")
  20.  
  21. ==========================================
  22. 03. Sum Numbers
  23.  
  24. init_num = int(input())
  25.  
  26. sum = 0
  27. while sum < init_num:
  28. current_num = int(input())
  29. sum = sum + current_num
  30.  
  31. print(sum)
  32.  
  33. ==========================================
  34. 04. Sequence 2k+1
  35.  
  36. n = int(input())
  37.  
  38. current_num = 1
  39. while current_num <= n:
  40. print(current_num)
  41. current_num = current_num * 2 + 1
  42.  
  43. ==========================================
  44. 05. Account Balance
  45.  
  46. input_line = input()
  47.  
  48. balance = 0
  49. while input_line != "NoMoreMoney":
  50. amount = float(input_line)
  51. if amount < 0:
  52. print("Invalid operation!")
  53. break
  54.  
  55. balance = balance + amount
  56. print(f"Increase: {amount:.2f}")
  57.  
  58. input_line = input()
  59.  
  60. print(f"Total: {balance:.2f}")
  61.  
  62. ==========================================
  63. 06. Max Number
  64.  
  65. import sys
  66.  
  67. line = input()
  68.  
  69. max_num = -sys.maxsize
  70. while line != "Stop":
  71. current_num = int(line)
  72.  
  73. if current_num > max_num:
  74. max_num = current_num
  75.  
  76. line = input()
  77.  
  78. print(max_num)
  79.  
  80. ==========================================
  81. 07. Min Number
  82.  
  83. import sys
  84.  
  85. line = input()
  86.  
  87. min_num = sys.maxsize
  88. while line != "Stop":
  89. current_num = int(line)
  90.  
  91. if current_num < min_num:
  92. min_num = current_num
  93.  
  94. line = input()
  95.  
  96. print(min_num)
  97.  
  98. ==========================================
  99. 08. Graduation
  100.  
  101. student_name = input()
  102.  
  103. year = 1
  104. sum = 0
  105. fail_count = 0
  106. while year <= 12:
  107. if fail_count > 1:
  108. break
  109.  
  110. grade = float(input())
  111.  
  112. if grade < 4:
  113. fail_count += 1
  114. continue
  115.  
  116. sum = sum + grade
  117.  
  118. year += 1
  119.  
  120. if fail_count > 1:
  121. print(f"{student_name} has been excluded at {year} grade")
  122. else:
  123. avg_grade = sum / 12
  124. print(f"{student_name} graduated. Average grade: {avg_grade:.2f}")
  125.  
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement