跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 大佬们,一个关于 list 的作业不会做,求指导
未分類
15 10 月 2020

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

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

資深大佬 : gypsy 3

就是把用户输入的 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.

大佬有話說 (5)

  • 資深大佬 : learningman

    代写作业,50 一位

  • 資深大佬 : qefrgty

    先想办法取 list 的元素,

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

    然后打印变量个星号。

    emmmm…这是最基本的思路了吧…

  • 資深大佬 : user8341

    作业要自己做啊。你这些问题简单 Google 一下就有解答的:

    www.geeksforgeeks.org/python-get-a-list-as-input-from-user/

    www.w3resource.com/python-exercises/python-basic-exercise-26.php

  • 資深大佬 : lambdafate

    1. “Write a function that takes a list of numbers as parameters. “. 不需要 input 吧,list 作为函数参数传进来
    2. 可以这样 >>> “*” * n # n 是一个整数

  • 主 資深大佬 : gypsy

    @learningman
    @qefrgty
    @user8341
    @lambdafate

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

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

    def star(a):
    return “*” * a

    for i in list:
    print(star(i))

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具