-1

`'''I'm new in Python and I've just started Python 3.9, but I wrote the following Python code, but it doesn't work properly and it gives me the following error: (I apologize in advance for writing my own English grammar) unsupported operand type(s) for -: 'str' and 'str' The question is to calculate the hourly delay of 20 employees, which should be written with the function and class for 20 people, so that two random numbers from each of the 20 people in the two time slots of 12-12 and 17-13 are written with the random function, but except for Thursday, which is only between 8:00-13:00 should take a random input time slot. And then add up the time delay of each person in one week and print their delay and do it in order until the 20th person and for each person the delay of each person is printed as the number of days or hours of delay. I wrote the code, but the problem is that it gives a TypeError and says that these calculations are not possible for the string.'''

import random
c=0
def weeklyPaid(delays):
    if delays >8:
        return delays / 8
    else:
        return delays * 1

while c<=20:
    sat1 = input(random.randint(8, 12))
    sun1 = input(random.randint(8, 12))
    mon1 = input(random.randint(8, 12))
    tue1 = input(random.randint(8, 12))
    wed1 = input(random.randint(8, 12))
    thu1 = input(random.randint(8, 12))


sat2 = input(random.randint(13, 17))
sun2 = input(random.randint(13, 17))
mon2 = input(random.randint(13, 17))
tue2 = input(random.randint(13, 17))
wed2 = input(random.randint(13, 17))
thu2 = input(random.randint(13, 13))


delays = (sat2-sat1*1-8-1) + (sun2-sun1*1-8-1) +(mon2-mon1*1-8-1) + (tue2-tue1*1-8-1) + (wed2-wed1*1-8-1) + (thu2-thu1*1-8-1)

print("person delays","no",c+1, "=",delays)
c = c + 1
1

1 Answer 1

0

"If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. "

this is from python docs. so I thought the reason of your issure is the type of the value from input is 'string', it can't plus with numbers. your can use int() method to solve the problem.

e.g, sat2 = int(input(……))

a good method is use type(), when you are not sure the variant's type.

2
  • Thank you for your guidance. The string method also did not answer and gives a new error. Feb 4 at 19:05
  • sorry, there is error in my post. it shouldn't use str(), but int(). i mean we need to convert the inputed values 's type from string to integer.
    – Brantdu
    Feb 5 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.