Question

DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a...

DATA PROGRAMMING: PYTHON

Be sure to use sys.argv NOT input.


Write a program and create a function called inch2cm that takes one number in inches as a parameter, converts it to the centimeters and prints the result. The program output is shown below.

Input: 14

Output:

14 inches = 35.56 centimeter


Write a program and create the following functions:
shapes(): takes the shape name and a number as parameters, and calls the proper function to calculate the area.
areaCircle(): take one number as a parameter, calculates the area of the circle, and print the result. Round the output to 2 decimal places.
areaSquare(): takes one number as a parameter, calculates the area of the circle, and prints the result. Round the output to 2 decimal places.
You can assume the shape names will be circle or square (nothing else). The program output is shown below.

Input:

10

5

Output:

a) The circle area is 314.16

b) The square are is 25


Write a program and create a function called isOdd that takes a number and determine it is an odd number or not. The program output is shown below.

Input:

9

10

Output:

a) 9 is an odd number

b) 10 is not an odd number


Write a program and create a function called calc. The function generates a random integer number between 10 and 100, and determines it is divisible y 6 or not, and prints the result. The output is shown below.

Output:

a) 55 is not divisible by 6

b) 72 is divisble by 6

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

1)ans..

CODE:

import sys
def inch2cm(n):
   print("{0} inches = {1}".format(n,2.54*n)," centimeter")
input = sys.argv[1]
inch2cm(int(input))

2)

CODE:

import sys
import math
def areaCircle(r):
   print("The circle are is ",round(math.pi*r**2,2))

def areaSquare(r):
   print("The square area is",round(r*r,2))
def shape(name,r):
   if(name=="circle"):
       areaCircle(r)
   else:
       areaSquare(r)
r = sys.argv[1]
s =sys.argv[2]
shape("circle",int(r))
shape("square",int(s))

3)ans..

CODE:

import sys
def isOdd(n):
   if n%2!=0:
       print("{0} is an odd number".format(n))
   else:
       print("{0} is not an odd number".format(n))

input = sys.argv[1]
isOdd(int(input))

4)

CODE:

import random
def calc():
   r = random.randrange(10, 100)
   if r%6==0:
       print(r," is divisible by 6")
   else:
       print(r," is not divisible by 6")

calc()

OUTPUT:

If you have any doubts please COMMENT...

If you understand the answer please give THUMBS UP..

Add a comment
Know the answer?
Add Answer to:
DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a...
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
  • PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random...

    PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20

  • Data Programming l: Python Write a program that calculates how much Mary should pay for buying...

    Data Programming l: Python Write a program that calculates how much Mary should pay for buying 3 KitKat each worth $2 and 2 Twix chocolate each worth $4. Output: Mary should pay $14. Write a program that takes the circle radius and compute the circle area. Use the round function to have at most 2 decimal places in the output. Output: The area of a circle with 4 inches radius is 50.27

  • How to solve it using Python? 5. Write a function called no_squares which takes an input...

    How to solve it using Python? 5. Write a function called no_squares which takes an input parameter N, a positive integer, and returns: 1 if N is not divisible by a square and has an even number of prime factors -1 if N is not divisible by a square and has an odd number of prime factors 0 if N is divisible by a square For example, no-squares (10) returns 1 (since 10 = 2x5), no-squares (30) returns-1 (since 30...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

  • The program will need to accept two input arguments: the path of the input file and...

    The program will need to accept two input arguments: the path of the input file and the path of the output file. See etc/cpp/example.ifstream.cpp for the basis of how to do this. Once the input and output file paths have been received, the program will need to open the input and output files, read and process each input file line and create a corresponding output file line, close the input and output files, and then create and output some summary...

  • Using Python Write the following well-documented (commented) program. Create a class called Shape that has a...

    Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....

  • C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program...

    C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program that calculates the Area of a cirele, a square and a rectangle. Your program must prompt the user to select which area is to be calculated. Document your program. Apply the do while loop to repeat the program Apply the while loop for input validation. Apply the switch statements or the if/ else if statement to prompt the user for the area's selection. Based...

  • Use C programming Make sure everything works well only upload Write a program that takes an...

    Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...

  • Use PYTHON3 to create a program that asks the user for their name, and then prints...

    Use PYTHON3 to create a program that asks the user for their name, and then prints their initials. You must create a function called getInitials() that takes the name string and prints out the initials. It must be case insensitive and the initials must be printed in upper case. The program must contain a main() and a function called getInitials(), implemented as described in the function header comment given below. (You should include this function header comment in your own...

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