Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON # Follow the directions below. Add your code below the starter # code to complete the assignment as directed. # # This homework covers

PYTHON

# Follow the directions below. Add your code below the "starter"

# code to complete the assignment as directed.

#

# This homework covers Chapter 5: Conditionals, Loops, And Some Other Statements

# 1. Write a program that accepts the lengths of three sides of a triangle as inputs.

# The program output should indicate whether or not the triangle is an equilateral triangle.

# If is is NOT equilateral, indicate so and then print the largest side.

# Example:

# Enter the first side: 4

# Enter the second side: 4

# Enter the third side: 4

# The triangle is equilateral

# Enter the first side: 6

# Enter the second side: 5

# Enter the third side: 12

# The triangle is not equilateral

# Its largest side is 12

# 2. Write a conditional that checks the string in_2 for a period ('.').

# If it is present then print '[+] found period' and then checks for

# a tilde ('~') and if present then print '[+] found tilde'. Print

# '[-] nothing found' if there is not a period of a tilde in the

# string.

# Example:

# Enter a string: test

# [-] nothing found

# Enter a string: file.pdf

# [+] period found

# Enter a string: ~\test.txt

# [+] tilde found

# [+] period found

in_2 = input('Enter a string: ')

# 3. Create three count variables: count_char, count_digit, count_punc. Iterate

# over the hw03_str string. If the character is alphabetical

# (A-Za-z) increment the count_char counter. If the character is a digit (0-9)

# increment the count_digit counter. If the character is punctuation

# (!@#$%^&*()_+-={}[]|) the increment the count_punc counter.

# Ignore all other characters. Print the counter names and the counts when

# the iteration is complete.

# Example:

# count_char: 329

# count_digit: 63

# count_punc: 108

hw03_str = 'Tmg6A_QEi2yVdEgl=DOrq]h4IY%=zC1-94+8q9Ozs|}!!xW=h^wUJl(pF6KsFemZqW+Fdy2sP]elpqDno#9t9fhotD%0ipvX6WAwGMb[JKk410jDN3CTFN1e0Kgtlyqn]VZO!t3U|}LbW_rTUIHSv{A@egd^cVO^VOAO-(zF2DyzVNW(j6mt#ffSND&)Rq(]bXc$}[gBfS9NZtfu#AQxINke@ek+Z#dVp5-b6Ieci+3FJeZfgTUY#w83rmncmp]C33|7hhH#(#e97v*5Zw2NYR^&1F1dNz%qODNb0Z0{TDZjLE6[aPWPEsiY6&bwd3#2GirxPTKBJC[3@7sVDh(h7JK2S_]{t*1#j$1U-wGp}Mwq]JdpnPUCGL26XsJ#Jm@02HXkPxYg=g&c+$l2!{0IbSciM!&]C@H)AS*l_pI{Xgo&Mf|q[B_MnU)GLUb$tZiLbJmdf${5voIs9Y{s$NJR%-NS4PA=ot@f^X2a01fs[4}{#Ip$zq[y'

# 4. Write a conditional to check if in_4 is a float or an integer. Print

# '[+] integer' if in_4 is an integer and'[+] float' if the number

# if a float.

# Example:

# Enter a number for problem 4 (integer or float): 4

# [+] integer

# Enter a number for problem 4 (integer or float): 3.14

# [+] float

in_4 = input('Enter a number for problem 4 (integer or float): ')

# 5. Write a program using a while loop that asks the user for a number or to just enter to quit the program.

# If the user just hits the enter key with no number, the program should exit.

# If the user enters something other than a number, the program should display "NOT A NUMBER".

# If the user enters a number, the program should multiply the entered number by a running product.

# At the end, the program should display the final product.

# ONLY allow integers. DISPLAY the product with no decimal places.

# Example:

# Enter a number or just enter to quit: 5

# Enter a number or just enter to quit: 5

# Enter a number or just enter to quit: two

# NOT A NUMBER

# Enter a number or just enter to quit: 3

# Enter a number or just enter to quit:

# The product is: 75

# CHALLENGE: (i.e., you REALLY, REALLY, REALLY SHOULD try this)

# At the end, display all of the entered numbers

# Example (from above):

# 5 x 5 x 3 = 75

# HINT: start with an empty list. append each number as the user enters it. use the join method to

# concatenate the list elements together with a ' + '

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

More Books

Students also viewed these Databases questions