0

I have the following code which does not list out the bedrooms or baths with the number :

room = ('Bath','BedRoom')

for k in range(0-6):
    room = room[1] = str(1+k)
    print room

I wanted to see the output as 'Bedroom1','Bedroom2'...............'Bedroom6'

I am not sure what I am doing wrong here and appreciate your inputs.

Thanks!

1 Answer 1

2
room = ('Bath','BedRoom')
for k in range(1,7):
    print room[1] + str(k)

Note that range(0-6) evaluates to range(-6) because it is doing 0 - 6 as subtraction.

Output

BedRoom1
BedRoom2
BedRoom3
BedRoom4
BedRoom5
BedRoom6
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.