Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Simplify code given import random fave_number - 1 #doing some calculations on this number new_fave - fave_number + fave_number new fave - new_fave 2 new
Simplify code given
import random fave_number - 1 #doing some calculations on this number new_fave - fave_number + fave_number new fave - new_fave 2 new fave - new_fave - 5 new fave - new_fave + 123456 print(new_fave) #check if new_fave is divisible by 5 div_by_5 - False if (new_fave % 5 -- %): div_by_5 - True else: div_by_5 - False if (div_by_5 - True): print("Is new fave number divisible by 5? True") elif (div_by_5 -- False): print("Is new fave number divisible by 57 False") fave_number_2 - 42 # doing the same calculations as above on this number new_fave_2 - fave_number_2 + fave_number_2 new_fave_2 - new_fave_2 2 new_fave_2 - new_fave_2 .. 5 new_fave_2 - new_fave_2 + 123456 print(new_fave 2) # check if new_fave_2 is divisible by 5 div_by_5 - False if (new_fave_2 % 5 -- ): div_by_5 - True else: div_by_5 - False if (div_by_5 -- True): print("Is new fave number #2 divisible by 5? True") elif (div_by_5 - False): print("Is new fave number #2 divisible by 5? False") fave_word - "hello # add 'world and a random number (between 6-3) of 'Bob's to this word fave_word + "world" rand_num - random.randint(0.3) if rand_num - 8: fave_word - elif rand_num - 1: fave_word + "Bob" TOVOU # add 'world' and a random number (between 0-3) of 'Bob's to this word fave_word + "world" rand_nun - randon.randint(0,3) if rand_num =- : fave_word + F elif rand_num - 1: fave_word +- "Bob elif rand_nun - 2: fave_word + "BobBob" elif rand_num -- 3: fave_word + 'BobBobBob" Lelser fave_word += " print(fave_word) fave_word_2 - 'csc108 # add 'world' and a random number (between 6-3) of 'Bob's to this word fave_word_2 += "world" rand_num - random.randint(0,3) fif rand_num =- : fave_word_2 +- elif rand_num 1: fave word 2 - Bob! elif rand_num = 2: fave_word_2 +- 'BobBob elif rand_num= 3: fave_word_2 += 'BobBobBob fave_word_2 + print(fave_word_2) fave_word_3 - 'catz # add 'world and a random number (between 0-3) of 'Bob's to this word fave_word_3 + "world" rand_num= random.randint(0,3) rand_num : fave_word_3 + 1 elif rand_num 1: fave_word_3 Bob! elif rand_num= 2: fave_word 3 + "BobBob El rand_num 3: fave_word_3 + BobBobBob fave_word_3 + print(fave_word 3) Warmup: Cleaning Up Code Your friend, Bob, has written a random program, playing around with the basics of Python. But for such simple operations, he feels as though his file is way too long. He remembers hearing from someone that, when you're trying to program something really simple, you'll often find that "long code is wrong code". Even if the code is working properly, making it shorter would make it much better and cleaner to handle. Bob's file is named al_warmup.py. All Bob wants is to make the file shorter. He doesn't want the way the code works to change. Could you clean up this code for him, using functions and getting rid of other useless things? (For example, by putting all the mathematical calculations into one equation instead of splitting each step up, or, when checking if a boolean value is True, instead of writing the redundant code 'if (bool == True), simply writing 'if (bool), etc.). Try to get the file down to less than 40 lines. This part of the assignment is just a warm-up exercise and will not be graded for correctness, but for participation/effort, so don't worry too much about details/accuracy, and spend a little bit of time practicing the art of cleaning up bad code. Part 1: Compatibility Calculator Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started