Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Try to get the code down to less than 40 lines. (PYTHON) import random fave_number = 1 # doing some calculations on this number new_fave

Try to get the code down to less than 40 lines. (PYTHON)

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 == 0): 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 5? 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 == 0): 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 0-3) of 'Bob's to this word fave_word += "world" rand_num = random.randint(0,3) if rand_num == 0: fave_word += '' elif rand_num == 1: fave_word += 'Bob' elif rand_num == 2: fave_word += 'BobBob' elif rand_num == 3: fave_word += 'BobBobBob' else: fave_word += '' print(fave_word)

fave_word_2 = 'csc108' # add 'world' and a random number (between 0-3) of 'Bob's to this word fave_word_2 += "world" rand_num = random.randint(0,3) if rand_num == 0: 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' else: 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) if rand_num == 0: fave_word_3 += '' elif rand_num == 1: fave_word_3 += 'Bob' elif rand_num == 2: fave_word_3 += 'BobBob' elif rand_num == 3: fave_word_3 += 'BobBobBob' else: fave_word_3 += '' print(fave_word_3)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions