Python:关于我下一步该做什么有什么线索吗?附件是我的作业编号

2024-06-01 05:40:05 发布

您现在位置:Python中文网/ 问答频道 /正文

作业问题是: 当你(或你的父母)从cd上翻录歌曲时,数字文件是通过以一定的速率对声音进行采样来创建的。常用速率为128kbps(每秒128 x 2^10位)、192、256。编写一个函数“def songs(capacity,bitrate)”,返回某人可以在ipod上播放的4分钟歌曲数。该函数的两个参数是ipod的容量(GB)和采样率(kbps)。千兆字节是2^30字节,一个字节包含8位。还要编写一个完整的程序(带有一个main函数),使用I“Input”函数获取这两个值,将它们传递给songs函数,然后打印歌曲的数量。你知道吗

下面是我的代码 我觉得我错过了一半的东西,我需要完成的功能,但我不知道如何编码他们。非常感谢您的帮助。我使用的是python3.6

"""Chapter 3 assignment
Purpose: To complete the tasks assigned in the chapter 3 assignments folder
Author: Dominic Gigli
Date Created 15 Feb 2018
"""

def main():
    def songs(capacity, bitrate):
        """The point of this program is to find out how many 4 minute songs can fit on an ipod. It will multiply capacity and bitrate and take the users storage size input and the out
        put will display how many songs fit. parameters will be capacity, bitrate"""

    # capacity: The size of the device in question
    #  bitrate: The sampling rate in kbps
    #  Length of songs: The time of the songs are 4 minutes
    # return: the number of songs that can be stored\

    capacity = int(input('enter the size of the storage on the ipod: '))
    bitrate = int(input('enter the rate of transfer (common rates are 128, 192, 256 kbps):'))
    answer = capacity * bitrate
    print('The number of songs that can fit are', answer)


main()

Tags: ofthe函数in字节maindef歌曲