Top Posters
Since Sunday
g
2
2
2
1
New Topic  
S.v S.v
wrote...
Posts: 54
Rep: 3 0
A year ago
Ian hates doing his laundry. But he loves to wear a clean t-shirt every day. He also loves to attend
different programming events where he receives a new (clean) t-shirt.
Ian starts with N clean t-shirts. The number of events coming up is M in the next D days. These
three parameters will be the first line of the program input.
The second line of the input will be the days with scheduled events: day 1, day 5, day 16 and so on.
The number of these days must match the M.
The output: the number of times that Ian will have to do the laundry in the next D days.
 
I tried starting it like this:

T = int(input("Number of clean original T-shirts:"))
while True:
    if T<0:
        T = int(input("Incorrect. Number of clean original T-shirts:"))
        continue
    else:
        break
event = int(input("Number of Events coming up:"))
day = int(input("How many days are the events spread over:"))
while True:
    if event > day:
        event = int(input("Incorrect. Number of Events coming up:"))
        day = int(input("Incorrect. How many days are the events spread over:"))
        continue
    else:
        break

but I dont know what to do after
Read 750 times
22 Replies
Replies
Anonymous
wrote...
A year ago
Code:
# Taking input for days with scheduled events
event_days = []
for i in range(event):
    day_number = int(input(f"Enter day number for event {i+1}: "))
    event_days.append(day_number)

# Sorting the event days in ascending order
event_days.sort()

# Counting the number of times Ian needs to do laundry
laundry_count = 0
current_tshirts = T

for i in range(1, day+1):
    if i in event_days:
        # Ian attends an event on this day
        current_tshirts += 1  # Ian receives a new clean t-shirt
    else:
        # Ian doesn't have an event on this day
        if current_tshirts == 0:
            # Ian has no clean t-shirts, needs to do laundry
            laundry_count += 1
            current_tshirts = T  # Reset the count after doing laundry
        else:
            current_tshirts -= 1  # Ian wears a clean t-shirt

# Output the result
print("Ian will have to do laundry", laundry_count, "times in the next", day, "days.")
S.v Author
wrote...
A year ago
line 3, in <module>
    for i in range(event):
NameError: name 'event' is not defined

this is what i got
Anonymous
wrote...
A year ago
Opps!

Code:
# Taking input for days with scheduled events
event = int(input("Number of Events coming up:"))
day = int(input("How many days are the events spread over:"))

event_days = []
for i in range(event):
    day_number = int(input(f"Enter day number for event {i+1}: "))
    event_days.append(day_number)

# Sorting the event days in ascending order
event_days.sort()

# Counting the number of times Ian needs to do laundry
laundry_count = 0
current_tshirts = T

for i in range(1, day+1):
    if i in event_days:
        # Ian attends an event on this day
        current_tshirts += 1  # Ian receives a new clean t-shirt
    else:
        # Ian doesn't have an event on this day
        if current_tshirts == 0:
            # Ian has no clean t-shirts, needs to do laundry
            laundry_count += 1
            current_tshirts = T  # Reset the count after doing laundry
        else:
            current_tshirts -= 1  # Ian wears a clean t-shirt

# Output the result
print("Ian will have to do laundry", laundry_count, "times in the next", day, "days.")

Try this!
S.v Author
wrote...
A year ago
I got this :

line 15, in <module>
    current_tshirts = T
NameError: name 'T' is not defined

Also I think that you have to ask how many tshirts ian has
According to the teacher:

The input will be 1 1 10 10 and the output will be 9
Basically 1 clean shirt, 1 event, 10 days, event on day 10.
Anonymous
wrote...
A year ago
Try this code

Code:
# Taking input for the initial number of clean T-shirts
T = int(input("Number of clean original T-shirts:"))
while True:
    if T <= 0:
        T = int(input("Incorrect. Number of clean original T-shirts must be greater than 0:"))
        continue
    else:
        break

# Taking input for other parameters
event = int(input("Number of Events coming up:"))
day = int(input("How many days are the events spread over:"))

# Taking input for days with scheduled events
event_days = []
for i in range(event):
    day_number = int(input(f"Enter day number for event {i+1}: "))
    event_days.append(day_number)

# Sorting the event days in ascending order
event_days.sort()

# Counting the number of times Ian needs to do laundry
laundry_count = 0
current_tshirts = T

for i in range(1, day+1):
    if i in event_days:
        # Ian attends an event on this day
        current_tshirts += 1  # Ian receives a new clean t-shirt
    else:
        # Ian doesn't have an event on this day
        if current_tshirts == 0:
            # Ian has no clean t-shirts, needs to do laundry
            laundry_count += 1
            current_tshirts = T  # Reset the count after doing laundry
        else:
            current_tshirts -= 1  # Ian wears a clean t-shirt

# Output the result
print("Ian will have to do laundry", laundry_count, "times in the next", day, "days.")

PS: Coding is not my speciality
S.v Author
wrote...
A year ago
No problem I think you are getting very close, it just doesnt give the correct number:

Number of clean original T-shirts:1
Number of Events coming up:1
How many days are the events spread over:10
Enter day number for event 1: 10
Ian will have to do laundry 4 times in the next 10 days.

He should be doing the laundry 9 times
Anonymous
wrote...
A year ago
Code:
# Taking input for the initial number of clean T-shirts
T = int(input("Number of clean original T-shirts:"))
while T <= 0:
    T = int(input("Incorrect. Number of clean original T-shirts must be greater than 0:"))

# Taking input for other parameters
event = int(input("Number of Events coming up:"))
day = int(input("How many days are the events spread over:"))

# Taking input for days with scheduled events
event_days = []
for i in range(event):
    day_number = int(input(f"Enter day number for event {i+1}: "))
    event_days.append(day_number)

# Sorting the event days in ascending order
event_days.sort()

# Counting the number of times Ian needs to do laundry
laundry_count = 0
current_tshirts = T

for i in range(1, day+1):
    if i in event_days:
        # Ian attends an event on this day
        current_tshirts += 1  # Ian receives a new clean t-shirt
    else:
        # Ian doesn't have an event on this day
        if current_tshirts == 0:
            # Ian has no clean t-shirts, needs to do laundry
            laundry_count += 1
            current_tshirts = 1  # Ian starts the day with a clean t-shirt
        else:
            current_tshirts -= 1  # Ian wears a clean t-shirt

# Output the result
print("Ian will have to do laundry", laundry_count, "times in the next", day, "days.")

last attempt Confounded Face
S.v Author
wrote...
A year ago Edited: A year ago, S.v
hey I got the exact same issue with the same number(kinda funny)

Number of clean original T-shirts:1
Number of Events coming up:1
How many days are the events spread over:10
Enter day number for event 1: 10
Ian will have to do laundry 4 times in the next 10 days.

as i said b4 its supposed to be 9
Post Merge: A year ago

I was thinking what if you make a total shirt number, and also on an event day shouldnt you add one to total number of shirts and add one dirty shirt?
Anonymous
wrote...
A year ago
One last shot:

Code:
# Taking input for the initial number of clean T-shirts
T = int(input("Number of clean original T-shirts:"))
while T <= 0:
    T = int(input("Incorrect. Number of clean original T-shirts must be greater than 0:"))

# Taking input for other parameters
event = int(input("Number of Events coming up:"))
day = int(input("How many days are the events spread over:"))

# Taking input for days with scheduled events
event_days = []
for i in range(event):
    day_number = int(input(f"Enter day number for event {i+1}: "))
    event_days.append(day_number)

# Sorting the event days in ascending order
event_days.sort()

# Counting the number of times Ian needs to do laundry
laundry_count = 0
current_tshirts = T  # Initialize with original number of clean T-shirts
total_tshirts = T    # Total number of T-shirts Ian has including clean and dirty ones

for i in range(1, day+1):
    if i in event_days:
        # Ian attends an event on this day
        total_tshirts += 1  # Ian receives a new clean t-shirt
        current_tshirts += 1  # Ian receives a new clean t-shirt
    else:
        # Ian doesn't have an event on this day
        if current_tshirts == 0:
            # Ian has no clean t-shirts, needs to do laundry
            laundry_count += 1
            current_tshirts = total_tshirts  # Reset to total count after doing laundry
            current_tshirts -= 1  # Ian wears a clean t-shirt
        else:
            current_tshirts -= 1  # Ian wears a clean t-shirt

# Output the result
print("Ian will have to do laundry", laundry_count, "times in the next", day, "days.")
S.v Author
wrote...
A year ago
OK THATS IMPROVEMENT

Number of clean original T-shirts:1
Number of Events coming up:1
How many days are the events spread over:10
Enter day number for event 1: 10
Ian will have to do laundry 8 times in the next 10 days.

the actual answer is 9 you're getting closer  Grinning Face
Anonymous
wrote...
A year ago
Does this one work?

How do you test your Python code? Do you use an online parser?

Code:
# Taking input for the initial number of clean T-shirts
T = int(input("Number of clean original T-shirts:"))
while T <= 0:
    T = int(input("Incorrect. Number of clean original T-shirts must be greater than 0:"))

# Taking input for other parameters
event = int(input("Number of Events coming up:"))
day = int(input("How many days are the events spread over:"))

# Taking input for days with scheduled events
event_days = []
for i in range(event):
    day_number = int(input(f"Enter day number for event {i+1}: "))
    event_days.append(day_number)

# Sorting the event days in ascending order
event_days.sort()

# Counting the number of times Ian needs to do laundry
laundry_count = 0
current_tshirts = T  # Initialize with original number of clean T-shirts

for i in range(1, day+1):
    if i in event_days:
        # Ian attends an event on this day
        current_tshirts += 1  # Ian receives a new clean t-shirt
    else:
        # Ian doesn't have an event on this day
        if current_tshirts == 0:
            # Ian has no clean t-shirts, needs to do laundry
            laundry_count += 1
            current_tshirts = 1  # Ian starts the day with a clean t-shirt
        else:
            current_tshirts -= 1  # Ian wears a clean t-shirt

# Output the result
print("Ian will have to do laundry", laundry_count, "times in the next", day, "days.")
S.v Author
wrote...
A year ago
nope went back to 4

Number of clean original T-shirts:1
Number of Events coming up:1
How many days are the events spread over:10
Enter day number for event 1: 10
Ian will have to do laundry 4 times in the next 10 days.

I downloaded the IDLE python shell thing on my computer
you can probably find it on the official python website
https://www.python.org/downloads/
Anonymous
wrote...
A year ago
Okay, with this code:

Code:
# Taking input for the initial number of clean T-shirts
T = int(input("Number of clean original T-shirts:"))
while T <= 0:
    T = int(input("Incorrect. Number of clean original T-shirts must be greater than 0:"))

# Taking input for other parameters
event = int(input("Number of Events coming up:"))
day = int(input("How many days are the events spread over:"))

# Taking input for days with scheduled events
event_days = []
for i in range(event):
    day_number = int(input(f"Enter day number for event {i+1}: "))
    event_days.append(day_number)

# Sorting the event days in ascending order
event_days.sort()

# Initialize variables
laundry_count = 0
days_until_event = event_days[0]  # Days until the next event
clean_tshirts = T  # Number of clean T-shirts Ian has

# Iterate through each day
for i in range(1, day+1):
    if i == days_until_event:
        # Ian attends an event on this day
        clean_tshirts += 1  # Ian receives a new clean t-shirt
        # Calculate the days until the next event
        if event_days:
            event_days.pop(0)  # Remove the first event day since it's already attended
            if event_days:
                days_until_event = event_days[0]
            else:
                days_until_event = float('inf')  # No more events
    else:
        # Ian doesn't have an event on this day
        if clean_tshirts == 0:
            # Ian has no clean t-shirts, needs to do laundry
            laundry_count += 1
            clean_tshirts = T  # Reset the count after doing laundry
        else:
            clean_tshirts -= 1  # Ian wears a clean t-shirt

# Output the result
print("Ian will have to do laundry", laundry_count, "times in the next", day, "days.")

I get:

  New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1692 People Browsing
Related Images
  
 4645
  
 443
  
 947
Your Opinion
Which industry do you think artificial intelligence (AI) will impact the most?
Votes: 798