Question

In: Computer Science

1-Please complete the below python programs. Use spaces for indentations since the website does not take...

1-Please complete the below python programs. Use spaces for indentations since the website does not take tabs.

#inputs to the function are 2 numbers x and y. Print "Sum 6!" if the sum of x and y is bigger or equal to 6. Print "Sum too small!" otherwise.

def sum_6(x,y):

#your answer here, can be multiple lines

___

#input to the function is a list of integers. The function will calculate and return a resultlist with the square of each number in the input list saved in it. For example: if mylist has numbers 1,2,3,4,5, the returned value should be a list with 1,4,9,16,25.

def square_num (mylist):

#your answer here, can be multiple lines

___

#in this main function, create a list with 6 numbers, call the second function in this question, print out the returned result.

def main ():

#your answer here, can be multiple lines

___

2-Write down the regular expression that can match: a string with 1 or more digits followed by exactly 2 small case letters. Sample string: 5678yr. (You do not need to consider the " ")

(same as the below question) Make sure you only write down the regex. Please do NOT include other things like / / around it. You do not need to consider any blanks before or after the regex, nor sentence starting/ending symbols.

Answer:

3-Write down the regular expression that can match: a float with 1 or more digits before the decimal point and exactly 2 digits after. Sample: 2345.34

(same as the below question) Make sure you only write down the regex. Please do NOT include other things like / / around it. You do not need to consider any blanks before or after the regex, nor sentence starting/ending symbols.

Answer:

Solutions

Expert Solution

#QUESTION 1:
Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.

Below is the output of the program:


Below is the code to copy:
#CODE STARTS HERE----------------
# 1 a.
def sum_6(x,y): #Function sum 6
   if x+y>=6: #Find if sum is greater than or equal to
      print("Sum 6!")
   else:
      print("Sum too small!")
sum_6(5,1) #Function called here

#1 b.
def square_num(mylist):
   new_list = [] #New list to store squared numbers
   for num in mylist: #Loop through the list
      new_list.append(num**2) #Store squared numbers in new_list
   return new_list #Return new list

#1 c.
def main(): #main function
   li = [1,2,3,4,5,6] #List created with 6 numbers
   print(square_num(li)) #Call square_num function and print returned result

main() #Main function call
#CODE ENDS HERE------------------

QUESTION 2:

REGULAR EXP: \d+[a-z]{2}

  • \d matches any digit character
  • '+' matches 1 or more occurence of preceding character
  • [a-z] matches any lowercase alphabet
  • {2} matches exactly 2 numbers of preceding characters

EXAMPLE:

MATCHES:

  • 12565464as
  • 55sa
  • 1ko

DOES NOT MATCH:

  • 45a4s
  • 554kkkk
  • jhh

QUESTION 3:

REGULAR EXP: \d+\.\d{2}

  • \d matches any digit character
  • '+' matches 1 or more occurence of preceding character
  • \. matches a '.'
  • {2} matches exactly 2 numbers of preceding characters

EXAMPLE:

MATCHES:

  • 45.45
  • 888888.99
  • 0.11
  • 115.25

DOES NOT MATCH:

  • 888
  • 122.3

Related Solutions

Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): A website requests an user to input his account password. Write a program to examize the validity of the password. The valid password must consists of: At least 1 letter in [a-z] At least 1 number in [0-9] At least a letter in [A-Z] (capital) At least one special letter in [$#@] At least...
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers)
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and...
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and show they will translate and run. Experience error messages when you enter bad syntax the interpreter cannot understand. Discussion: The best way to learn Python (or any programming language) is to write & run Python programs. In this lab you will enter two programs, and run them to produce the output. Then deliberately insert syntax errors to see what kinds of error messages you...
in python please Q1) Create a Singly link list and write Python Programs for the following...
in python please Q1) Create a Singly link list and write Python Programs for the following tasks: a. Delete the first node/item from the beginning of the link list b. Insert a node/item at the end of the link list c. Delete a node/item from a specific position in the link list Q2) Create a Singly link list and write a Python Program for the following tasks: a. Search a specific item in the linked list and return true if...
Problem 1. Complete the table below. Please use the spreadsheet for your convenience and to submit...
Problem 1. Complete the table below. Please use the spreadsheet for your convenience and to submit your responses. Given: total Fixed Costs = $60 (i.e., the fixed cost of $60 does not change with output). The price of the product is $55 Production Schedule for a widget firm Output (Q) Total Fixed Costs (TFC) Total Variable Cost               (VC) Total Cost (TC) Average Fixed Cost (AFC) Average Variable Cost (AVC) Average Total Costs (ATC) Total Revenue (TR) Profit 0 0 1...
Do it in python please! also please use this template please I have provided and below...
Do it in python please! also please use this template please I have provided and below is the activity def main(): # import the module random try: # asking the user to enter a number between 1 and 100 #loop time while if elif #for loop # generates that number of random integers and stores them in a list for x in # computations # displays the results on the screen # call try_Again to give the user the opportunity...
I did the complete programming in python , just want to use tkinter for GUI. please...
I did the complete programming in python , just want to use tkinter for GUI. please look at the 2nd part . i did some part of this program using tkinter but could not finis it. Thank you. import random image = 'w' # modified functions which accepts two numbers each and returns the respective # output def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def kidCalc():...
Section B—DIRECTIONS: Complete Problems 1 and 2 by recording your answers in the spaces provided. Use...
Section B—DIRECTIONS: Complete Problems 1 and 2 by recording your answers in the spaces provided. Use the following tax rates and taxable wage bases: Employees’ and Employer’s OASDI—6.2% both on $132,900; HI—1.45% for employees and employers on the total wages paid. Employees’ Supplemental HI of 0.9% on wages in excess of $200,000 was not applicable in these problems.    During 20--, Amanda Hines, president of Dunne, Inc., was paid a semimonthly salary of $7,100. Determine the following amounts. OASDI HI...
Please take the code below and add some javascript to it. Please use javascript inline. Please...
Please take the code below and add some javascript to it. Please use javascript inline. Please be sure to specify within the webpage with something like 'Click here' too show what was done and how to activate it. Please post in a format that can be directly copied. Thank you in advance HINT: add some fun widgets to the page index-css.html: <!DOCTYPE html> <html lang="en"> <head> <!-- title for web page --> <title>Index-CSS Page</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1">...
Please use the link below, which will take to an article, then summarize it. The summary...
Please use the link below, which will take to an article, then summarize it. The summary must be three fourths to one page long. Article name: IRS Offers in Compromise By: William A. Bottiglieri, JD, CPA Source:  https://www.cpajournal.com/2018/02/07/irs-offers-compromise/
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT