Question

Try to get the code down to less than 40 lines. (PYTHON) import random fave_number =...

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)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import random
def div_by_5(new_fave):
   return (new_fave % 5 == 0)
def make_word(fave_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 += ''
   return fave_word
fave_number = 1
# doing some calculations on this number
new_fave = (( (fave_number*2) * 2) ** 5) + 123456
print(new_fave)
# check if new_fave is divisible by 5
print("Is new fave number divisible by 5? "+str(div_by_5(new_fave)))
fave_number_2 = 42
# doing the same calculations as above on this number
new_fave_2 = (( (fave_number_2*2) * 2) ** 5) + 123456
print(new_fave_2)
# check if new_fave_2 is divisible by 5
print("Is new fave number divisible by 5? "+str(div_by_5(new_fave_2)))
fave_word = 'hello'
# add 'world' and a random number (between 0-3) of 'Bob's to this word
print(make_word(fave_word))
fave_word_2 = 'csc108'
# add 'world' and a random number (between 0-3) of 'Bob's to this word
print(make_word(fave_word_2))
fave_word_3 = 'catz'
# add 'world' and a random number (between 0-3) of 'Bob's to this word
print(make_word(fave_word_3))

Add a comment
Know the answer?
Add Answer to:
Try to get the code down to less than 40 lines. (PYTHON) import random fave_number =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import random fave_word = 'hello' # add 'world' and a random number (between 0-3) of 'Bob's...

    import random 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) Looking for a way to turn this into a function and cut down on redundant code. (python)

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

  • FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called...

    FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called guess my number.") print("The rules are: ") print("I think of a number and you'll have to guess it.") guess = random.randint(1, 5) print("You will have " + str(guess) + " guesses.") YourNumber = ??? unusedguesses=int(guess) while unusedguesses < guess:     if int(YourNumber) == number:         print("YAY, You have guessed my number")     else:         unusedguesses=int(guess)-1         if unusedguesses == 0:              break         else:             print("Try again!") print("The number was ", str(number))

  • on python i need to code a guessing game. After the player has guessed the random...

    on python i need to code a guessing game. After the player has guessed the random number correctly, prompt the user to enter their name. Record the names in a list along with how many tries it took them to reach the unknown number. Record the score for each name in another list. When the game is quit, show who won with the least amount of tries. this is what i have so far: #Guess The Number HW assignment import...

  • Hello, I am trying to solve the following problem using python: Assignment 3: Chatbot A chatbot...

    Hello, I am trying to solve the following problem using python: Assignment 3: Chatbot A chatbot is a computer program designed to emulate human conversation. For this program you will use if statements, user input, and random numbers to create a basic chatbot. Here is the scenario: You have decided to start an online website. You are creating a prototype to show investors so you can raise money and launch your website. You should ask the user at least 5...

  • import random def doTest(operation): ## complete your work here ##    # return True for now...

    import random def doTest(operation): ## complete your work here ##    # return True for now return True    responsesCorrect = 0 print("The software will process a test with 10 questions …… ") for compteur in range (10): operation = random.randint(0,1) if doTest(operation) == True: responsesCorrect += 1 print(responsesCorrect, "Correct responses")    if responsesCorrect <= 6 : print("Ask some help from your instructor.") else: print("Congratulations!") Requirement: You must use the format provided below and then complete the fill! Python! Thanks!...

  • Write a module of utility functions called util.py for manipulating 2-dimensional arrays of size 4x4. (These...

    Write a module of utility functions called util.py for manipulating 2-dimensional arrays of size 4x4. (These functions will be used in Question 3.) The functions you need to write are as follows: def create_grid(grid): """create a 4x4 array of zeroes within grid""" def print_grid (grid): """print out a 4x4 grid in 5-width columns within a box""" def check_lost (grid): """return True if there are no 0 values and there are no adjacent values that are equal; otherwise False""" def check_won...

  • how do I write this code without the imports? I don't know what pickle is or...

    how do I write this code without the imports? I don't know what pickle is or os.path import pickle # to save and load history (as binary objects) import os.path #to check if file exists # character value mapping values = {'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, ' S': 1,...

  • Search 12:40 pm Wed 13 Mar C Get Homework Help With c × Th| Assessment-CSSE1001 S...

    Search 12:40 pm Wed 13 Mar C Get Homework Help With c × Th| Assessment-CSSE1001 S × D https://mytut2.uqcloud.net × + 3 a mytut2.uqcloud.net Due: 20:30 15th Mar ﹀ [CSSE1001/7030] Introduction to Software Engineering (St Lucia) Semester 1, 2019-(4/43) completed if sign 2019 Save Attempt Reset Attempt Run Code 2 int string input('7 3 x--int (int_string) Week 2: Introductory Programming - (3/3) completed If Statements Using Elif and Else print( "monty" elif x-7 print( python) elif x 3: print( 'flying')...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT