xxlxxl 发表于 2020-8-25 17:02:52

加了条件

在for和if语句都不能用并且只能用一次while的情况下怎么打出来

Twilight6 发表于 2020-8-25 17:17:00

本帖最后由 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])))

疾风怪盗 发表于 2020-8-25 17:18:08

Twilight6 发表于 2020-8-25 17:17


楼主说:在for和if语句都不能用的情况下

baige 发表于 2020-8-25 17:22:33

output =
ans = ''
i = 0
row = 9
while row:
    ans += ' '*output + str(output) + '\n'
    i += 1
    row -= 1
   
print(ans,end='')

945318498 发表于 2020-8-25 17:27:31

虽然不知道研究这东西有啥用,不过勉强能实现吧。。

945318498 发表于 2020-8-25 17:29:12


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())

Twilight6 发表于 2020-8-25 17:31:07

疾风怪盗 发表于 2020-8-25 17:18
楼主说:在for和if语句都不能用的情况下

OK已经更正

945318498 发表于 2020-8-25 17:35:16

最后四个打印可以理解为写了一个函数把列表值依次弹出直至为空

945318498 发表于 2020-8-25 17:36:01

Twilight6 发表于 2020-8-25 17:31
OK已经更正

if不能用else就能用了么。。。

945318498 发表于 2020-8-25 17:36:35

Twilight6 发表于 2020-8-25 17:31
OK已经更正

说的是if语句都不能用哇

Twilight6 发表于 2020-8-25 17:39:23

945318498 发表于 2020-8-25 17:36
说的是if语句都不能用哇



哈哈我这里的 else 可以去掉,不影响的,因为我 while 循环里面没用 break

习惯掉自己加上 else 了,这是 while - else 语法,不是 if - else 哈

baige 发表于 2020-8-25 17:45:00

output =
ans = ''
row = 9
while row:
    ans += ' '*output + str(output) + '\n'
    row -= 1
print(ans)

sunrise085 发表于 2020-8-25 18:24:23

本帖最后由 sunrise085 于 2020-8-25 18:29 编辑

i=-4
while i<=4:
    print(' '*(4-abs(i)),(4-abs(i)),sep='')#数字前的空格个数就是数字,1之前有一个空格,2之前有两个空格……
    i+=1

Cool_Breeze 发表于 2020-8-25 18:49:21

#coding=utf-8

arr = ;
n = 8;
while n>-1:
    print(' '*arr + str(arr))
    n -= 1
页: [1]
查看完整版本: 加了条件