def main():
print("Enter a sequence of non-decreasing numbers.")
count = 0
last_num = float(input('Enter num: '))
cur_num = last_num
while cur_num >= last_num:
count += 1 #this line can go anywhere in body(while)
last_num = cur_num
cur_num = float(input('Enter num: '))
print("Thanks for playing")
print("sequence length: " + str(count))
(Suggested 15 minutes)
Write a program that asks the user to enter a sequence of "non-decreasing" numbers one at a time. Numbers are non-decreasing if each number is greater than or equal to the last.
When the user enters a number which is smaller than their previously entered value, the program is over. Tell the user how long their sequence was.
Here is an example (values entered by the user are bolded and italicized):
Enter a sequence of non-decreasing numbers.
Enter num: -1
Enter num: 0
Enter num: 1
Enter num: 3.12
Enter num: 99
Enter num: 99
Enter num: 42
Thanks for playing! Sequence length: 6
'python' 카테고리의 다른 글
#positional formationg, #named placeholder (0) | 2020.07.12 |
---|---|
list끼리 + 는 되지만 - 는 안된다? / append , extend 차이 (0) | 2020.06.17 |
"pithon" 을 "python"으로 바꾸기 (0) | 2020.06.16 |
print odd numbers (1 ~199) (0) | 2020.06.12 |