1.Lets see how the digits change in a number
255568 has digits either staying same or increasing. Lets call this an up number.
9854420 has digits either staying the same or decreasing. Lets call this a down number.
1357797543321 has digits going up and then down. We call such a number an updown number.
A number is valid if its an up number, a down number or an updown number.
The user will enter a number n. Output if it is valid.

2
.Ask the user to enter a number n >= 1.
There after the user will enter n-1 distinct integers between 1 and n. Thus, the entered numbers contain all numbers between 1 and n except one. Output the missing number.
You are not allowed to use lists. You are also not allowed to use dictionaries or any programming concept more advanced that a loop.
The numbers entered can be in any order.

————————————————
著作權宣告:本文為CSDN博主「lzy841398007」的原創文章,遵循 CC 4.0 BY-SA 著作權協議,轉載請附上原文出處鏈接及本宣告。
原文鏈接:https://blog.csdn.net/lzy841398007/article/details/103416348
uj5u.com熱心網友回復:
別沉啊 救救孩子吧uj5u.com熱心網友回復:
def checkNum(num):
state=None
times=0
m=None
while(True):
if num<10:
n=num
num=0
else:
n = num%10
num = num//10
if m==None:
m=n
continue
elif state==None:
if n < m:
state=True
m=n
continue
elif n>m:
state=False
m=n
continue
if (state and n>m) or (not state and n<m):
state = not state
times+=1
if times>1 or (times==1 and n>m):
return False
if num==0:
return True
m=n
print (checkNum(255568))
print (checkNum(9854420))
print (checkNum(1357797543321))
def findNum(n,arr):
num = 0
while n>1:
num=n^num^arr[n-2]
n-=1
return num^1
print (findNum(5,[1,2,3,5]))
uj5u.com熱心網友回復:
第一題
input_num = input('Please enter a n : ')
def str_filter(str_n, twich):
'''
將輸入字串重新排序,
如果如果重新排序和輸入一致,回傳True
否則,回傳False
'''
list_num = list(str_n)
if twich == 1:
sorted_list = sorted(list_num)
elif twich == 2:
sorted_list = sorted(list_num,reverse=True)
if sorted_list == list_num:
return True
else:
return False
max_str = max(sorted(input_num)) # 輸入字串中的最大值
max_str_index = list(input_num).index(max_str) # 最大字串索引值
# 單獨一個數位輸出有效
if len(input_num) == 1:
print('The number is vaild')
if str_filter(input_num, 1) or str_filter(input_num, 2):
print('The number is vaild')
# 字串最大值前邊符合升序,后邊符合降序。則符合updown number
elif str_filter(input_num[:max_str_index], 1) and str_filter(input_num[max_str_index:], 2):
print('The number is vaild')
else:
print('The number is not vaild')
順便問下樓主在哪里上學啊?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/120505.html
上一篇:python小題求大佬解答
