I have a mate who is moving into a new flat who has asked if it was possible to build a 'rigged' on demand name picker for the flat rooms. I have built this so far but I am getting errors for cyclomatic complexity (I can understand that, there's like 30 if/else loops in a row). I was just wondering what the proper way to go about assigning random numbers to integers, comparing them and then listing them in ascending order to a string.
The program should give anyone who enters a capital 'R' as their name a lower score therefore printing out that they choose the room last, once compared thru about 30 if/else statements to determine the which numbers are higher/lower (see below for example). The capital 'R' bit is so that you can enter everyones name in lowercase to prove the genuine randomness of the program, but then capitalize everyone's name on the real run thru (I'm sure there's sneakier techniques but its all I could come up with).
`if (name1 < name2 and name3 and name4):
print(flatmate1 + " chooses last")
elif (name2 < name1 and name3 and name4):
print(flatmate2 + " chooses last")
elif (name3 < name2 and name1 and name4):
print(flatmate3 + " chooses last")
elif (name4 < name2 and name3 and name1):
print(flatmate4 + " chooses last")`
Link to the full script https://pastebin.com/kuxcq6Bn
Any help would be greatly appreciated
Aucun commentaire:
Enregistrer un commentaire