Question

Create a Python script file called hw.py. Then import the module random:

from random import *

Ex. 1. Write a function called cleanLowerWord that receives a string as a paramcter and retums a new string that is a copy of

Thanks in advance!

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

Python 3.6.2 Shell File Edit Shell Debug Options Window Help Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC V. on w

editable code is given below but to maintain indentation please refer to image of code

import string
def isLower(ch):
return 'a'<=ch and ch<='z'
def isUpper(ch):
return 'A'<=ch and ch<='Z'
def toLower(ch):
if isUpper(ch):
return chr(ord(ch)+32)
else:
return ch
def toLowerStr(strn):
for cc in strn:
if cc in string.punctuation:
strn=strn.replace(cc,"")
for cc in strn:
if cc.isdigit():
strn=strn.replace(cc,"")
for cc in strn:
if cc==" ":
strn=strn.replace(cc,"")
lower=""
for ch in strn:
lower+=toLower(ch)
return lower
print(toLowerStr("Hello, User 15!"))


  

Add a comment
Know the answer?
Add Answer to:
Create a Python script file called hw.py. Then import the module random: from random import *...
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
  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

  • I need help with this exercise. Than you for the help. Language is C++ 2 Enumeration...

    I need help with this exercise. Than you for the help. Language is C++ 2 Enumeration Data Types Reformat is the shell of a program designed to read characters and process them in the following way Lowercase character Uppercase character Digit Blank Newline Any other character Converts to uppercase and writes the character Writes the character Writes the digit Writes a blank Writes newline Does nothing / Program Reformat reads characters from file DataIn and // writes them to DataOut...

  • Can someone help me with this? ## caesar.py def encode(msg, shift):    newmsg = ""   ...

    Can someone help me with this? ## caesar.py def encode(msg, shift):    newmsg = ""    #process each character in msg. #Hint: using a for loop    #A for loop to check each ch in msg: if ('A' <= ch and ch <= 'Z'): #if the character is an uppercase letter #encode the character based on the shift number    #Hint: the new character newch should be #chr((ord(ch) - ord('A') + shift) % 26 + ord('A'))    elif ('a' <=...

  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

  • Python program Use the provided shift function to create a caesar cipher program. Your program s...

    python program Use the provided shift function to create a caesar cipher program. Your program should have a menu to offer the following options: Read a file as current message Save current message Type in a new message Display current message "Encrypt" message Change the shift value For more details, see the comments in the provided code. NO GLOBAL VARIABLES! Complete the program found in assignment.py. You may not change any provided code. You may only complete the sections labeled:#YOUR...

  • General Requirements . . . Write a program that reads letters from a file called "letters.txt"....

    General Requirements . . . Write a program that reads letters from a file called "letters.txt". Your program will open the letters.txt file read in one character at a time For this assignment the test file will contain at least 30 letters, uppercase OR lowercase In your program you will change each letter (solution) to uppercase Use the function toupper in #include <ctype.h> You create a numerical version of the uppercase letter from the file . o Use int numberSolution...

  • 1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write...

    1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x):     if x in "aeiouyAEIOUY":         return True     else:...

  • You’ll create the parser with a 2-part layered approach. You’ll first create a Lexer, which will read characters from a file and output tokens. Then you’ll write the second part, which will process th...

    You’ll create the parser with a 2-part layered approach. You’ll first create a Lexer, which will read characters from a file and output tokens. Then you’ll write the second part, which will process the tokens and determine if there are errors in the program. This program have 3 files Lexer.java, Token.java, Parser.java Part 1 Lexer: The class Lexer should have the following methods: public constructor which takes a file name as a parameter○private getInput which reads the data from the...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • Create a Python script file called hw12.py. Add your name at the top as a comment,...

    Create a Python script file called hw12.py. Add your name at the top as a comment, along with the class name and date. Ex. 1. a. Texting Shortcuts When people are texting, they use shortcuts for faster typing. Consider the following list of shortcuts: For example, the sentence "see you before class" can be written as "c u b4 class". To encode a text using these shortcuts, we need to perform a replace of the text on the left with...

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