加了条件
在for和if语句都不能用并且只能用一次while的情况下怎么打出来 本帖最后由 Twilight6 于 2020-8-25 17:39 编辑user = int(input("Enter an interger:"))
temp,count = '',0
while -user != count:
temp += ' '*abs(count)+str(abs(count))+'\n'
count -= 1
print(temp + '\n'.join(sorted(temp.splitlines()[:-1]))) Twilight6 发表于 2020-8-25 17:17
楼主说:在for和if语句都不能用的情况下 output =
ans = ''
i = 0
row = 9
while row:
ans += ' '*output + str(output) + '\n'
i += 1
row -= 1
print(ans,end='') 虽然不知道研究这东西有啥用,不过勉强能实现吧。。
str1 = 0
str2 = ""
list1 = []
while int(str1) < 5:
str2 = int(str1) * "\0" + str(str1)
print(str2)
list1.append(str2)
str1 = int(str1) + 1
print(list1.pop())
print(list1.pop())
print(list1.pop())
print(list1.pop()) 疾风怪盗 发表于 2020-8-25 17:18
楼主说:在for和if语句都不能用的情况下
OK已经更正 最后四个打印可以理解为写了一个函数把列表值依次弹出直至为空 Twilight6 发表于 2020-8-25 17:31
OK已经更正
if不能用else就能用了么。。。 Twilight6 发表于 2020-8-25 17:31
OK已经更正
说的是if语句都不能用哇 945318498 发表于 2020-8-25 17:36
说的是if语句都不能用哇
哈哈我这里的 else 可以去掉,不影响的,因为我 while 循环里面没用 break
习惯掉自己加上 else 了,这是 while - else 语法,不是 if - else 哈
output =
ans = ''
row = 9
while row:
ans += ' '*output + str(output) + '\n'
row -= 1
print(ans) 本帖最后由 sunrise085 于 2020-8-25 18:29 编辑
i=-4
while i<=4:
print(' '*(4-abs(i)),(4-abs(i)),sep='')#数字前的空格个数就是数字,1之前有一个空格,2之前有两个空格……
i+=1
#coding=utf-8
arr = ;
n = 8;
while n>-1:
print(' '*arr + str(arr))
n -= 1
页:
[1]