大佬们,一个关于 list 的作业不会做,求指导 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
gypsy
V2EX    Python

大佬们,一个关于 list 的作业不会做,求指导

  •  
  •   gypsy 2020-10-20 20:48:17 +08:00 1827 次点击
    这是一个创建于 1864 天前的主题,其中的信息可能已经有所发展或是发生改变。
    就是把用户输入的 list 里的数字转换成 x 数量的星号。目前卡在两个地方
    1.input ()命令可以输入 list 吗?
    2. 可以直接用加减乘除来打印出相对应数量的星号吗?
    感谢

    Problem 2:
    Write a function that takes a list of numbers as parameters. Then print a histogram based on those numbers. Use asterisks to draw the histogram.
    For example, given the list [3, 7, 9, 5]. The function should produce the following:

    ***
    *******
    *********
    *****

    Call the function with the list [3, 7, 9, 5].
    Then call the function with the list [2, 0, 1].

    Hint: List was covered in the A3 notebook. We will formally discuss list in A5 notebook.
    You might want to first write the histogram code without a function. Then after code is working, write the code with a function. Please submit only the code with a function.
    learningman
        1
    learningman  
       2020-10-20 20:55:00 +08:00
    代写作业,50 一位
    qefrgty
        2
    qefrgty  
       2020-10-20 21:00:29 +08:00 via Android
    先想办法取 list 的元素,

    然后把这个元素赋值给一个变量,

    然后打印变量个星号。

    emmmm…这是最基本的思路了吧…
    9LCRwvU14033RHJo
        3
    9LCRwvU14033RHJo  
       2020-10-20 21:01:11 +08:00
    lambdafate
        4
    lambdafate  
       2020-10-20 21:04:53 +08:00
    1. "Write a function that takes a list of numbers as parameters. ". 不需要 input 吧,list 作为函数参数传进来
    2. 可以这样 >>> "*" * n # n 是一个整数
    gypsy
        5
    gypsy  
    OP
       2020-10-20 21:08:29 +08:00
    @learningman
    @qefrgty
    @user8341
    @lambdafate

    做完了,输出是对的,感谢。

    import ast
    list=ast.literal_eval(input())

    def star(a):
    return "*" * a

    for i in list:
    print(star(i))
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     933 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 21ms UTC 20:51 PVG 04:51 LAX 12:51 JFK 15:51
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86