Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bonus! Make your own Spongebob Font generator! Dont use that weird spongebob mocking meme Me: DonT uSe that Welrd SpoNgEboB MoCkinG MEme This is an

image text in transcribed
image text in transcribed
Bonus! Make your own Spongebob Font generator! "Dont use that weird spongebob mocking meme" Me: DonT uSe that Welrd SpoNgEboB MoCkinG MEme This is an optional, extra credit exercise for you to have fun with strings, conditionals, and while loops. You will need to submit this function in a separate file lab03_bonus.py to a separate Gradescope assignment Lab03: Bonus. This function is based off of the Mocking Spongebob Meme. Your task: to write a function that takes in a string message and returns the same message but so that it looks like the font from a Mocking Spongebob meme, meaning that it's letters are randomly uppercase or lowercase. But in Python, strings are immutable (i.e you cannot directly modify them by changing individual characters). For example: >>> word- "hello" >>> word(0] = "H" Traceback (most recent call last): File "spyshell#3>", line 1, in word[0] - "H" TypeError: 'str' object does not support item assignment Notice when we try to assign word [0) to be "H", we get an error. Because we cannot directly change/reassign the characters in the string message, we will instead declare an empty string variable called SpongebobText that we will add characters to one by one. We will access each character in message, decide whether to make a letter lowercase or uppercase, and then add it to SpongebobText. To decide whether or not to make a letter uppercase or lowercase, we will pick a random number between O and 10 (you'll see how to do that below). If that number is even, make the letter lowercase and add it to SpongebobText. Otherwise, make the letter uppercase and add it to SpongebobText. This function will require you to use Python functions you are probably unfamiliar with: two of them are somestr. lower() and someStr.upper(), where somestr is a string variable. Lower() takes a string variable and returns a lowercase version of it. upper() takes a string variable and returns an uppercase version of it. >>> word- "Hello" >> word[01. lower() "h' >>> print (word) "Hello' >>> word.upper() "HELLO' >> print(word) "Hello' Note that upper() or lower() do not modify the variable word: they return a new string with the characters that are either in lower or upper case.. You will also have to use random.randint (a, b) which returns a random integer N such that a >> random.randint (0, 5) >> random.randint (0, 7) For the spongebobFont () function, every time you index a character in message, you will want to generate a random integer between 0 and 10. Then, if that integer is even, you should add a lowercase version of that letter to SpongebobText. Otherwise, add an uppercase version of that letter to SpongeboText. Here is the starter code: import random def spongebobFont (message): - Given an input string, go through the string character by character and decide whether or not to make a specific character uppercase or lower case. -E.g., if message = "hello", first look at the first character 'h'. Then pick a random integer. If that integer is even, add a lowercase 'h' to SpongebobText. Otherwise, add an uppercase 'H' to SpongebobText. Do this for every character in message. SpongebobText = "" random.seed(7919) # This is the string we will add characters to and return at the end of our function # Do not edit this line! # This is the index variable we will use to index message while i

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

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions