获得程序没有输出的错误。 [英] Getting an error that program does not have output.

查看:127
本文介绍了获得程序没有输出的错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是:



编写一个程序,使用输入计算总薪酬,提示用户每小时和每小时的费率。在40小时以上工作的所有小时的小时费率奖励时间一半。将逻辑放在一个名为computepay()的函数中进行时间和半的计算,然后使用该函数进行计算。该函数应返回一个值。使用45小时和每小时10.50的速度来测试程序(工资应为498.75)。您应该使用input来读取字符串,使用float()将字符串转换为数字。除非您愿意,否则不要担心错误检查用户输入 - 您可以假设用户正确输入数字。不要命名你的变量总和或使用sum()函数。



我尝试过:



The question is:

Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Award time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.

What I have tried:

def computepay:
    if hrs<=40:
        pay= h*r
    elif hrs>40:
        pay= (h*r)+(h-40)*(1.5*r)
        
    return pay

hrs = input("Enter Hours:")
h= float(hrs)
rate= input("Enter Rate:")
r= float(rate)
p = computepay(h,r)
print(p)

推荐答案

这是无效的python:你的函数定义是错误的。

见这里: Python编程/功能 - 维基教科书,为开放世界打开书籍 [ ^ ]

Python函数定义需要参数 - 和小时里面的teh函数也应该是 h
It's not valid python: your function definition is wrong.
See here: Python Programming/Functions - Wikibooks, open books for an open world[^]
Python function definitions need the parameters - and hrs inside teh function should be h as well.


这篇关于获得程序没有输出的错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆