Python Answers

Questions answered by Experts: 5 288

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Write short note on following:


a) How to create One-dimensional array?


b) How to identify datatype for numpy array?

Multiply 8 with 4, and print the result.

a. Display this to the console:

Bananas: $0.50 each

Strawberries: $.75 each

b. Ask the user what they want to purchase. They will type an 'b' for bananas or an 's' for strawberries.

c. Your program will then ask for the number of bananas or strawberries they wish to purchase (depending on which they selected). The number of bananas cannot exceed 20 and the number of strawberries cannot exceed 10. If the user input exceeds these maximums your program should exit.

d. Your program should then print a report to the console like the following:

Item Qty Price Total

--------------------------

Bananas 4 $0.50 $2.00


Tax(15%): $0.30

Total Cost: $2.30

e. Ask the user for the amount tendered (the amount of money given for the payment). If the amount tendered is over $100 tell the user that there isn't enough change for such an amount and exit.

f. Finally, your program should print another report to the console like the following:

Amount tendered: $10

Change: $7.70

Thank you for shopping with SAI!


Counting Num

by CodeChum Admin

To give you more of a challenge with a number's digits, let's try counting how many of a certain digit is present on a given number.


Let's start coding!


Instructions:

  1. Input two integer values. The first one shall accept any integer from 0-9 and the other one shall take a non-zero positive integer.
  2. Using a while loop, count how many of the first integer (0-9) is present in the digits of the second inputted integer and print the result (see sample input and output for example).
  3. Tip #1: You have to use your knowledge from the previous problems in looping through the digits of a number: % 10 to get the rightmost digit, while / 10 to remove the rightmost digit. Make sure to solve the previous problems first.

Input

A line containing two integers separated by a space.

2·124218

Output

A line containing an integer.

2





Survival of the Biggest

by CodeChum Admin

Looping a number and taking away each digit of it is so much fun, but I wanted to try out a much more complex task: getting the largest digit among them all.

Think you can handle the job?


Instructions:

  1. Input a non-zero positive integer.
  2. Using the same concept as the previous problem, figure out how to separate the digits of a number and determine which of the digits is the largest one, using a while. Afterwards, print the largest digit.
  3. Tip #1: Create another variable that will hold the largest digit. Initial its value to a negative integer, like -1, outside the loop.
  4. Tip #2: Everytime you get the rightmost digit, check if it is greater than the current largest digit. If it is, set it as the new largest digit.

Input

A line containing an integer.

214

Output

A line containing an integer.

4





Place Values

by CodeChum Admin

Manipulating values from a series of numbers is fun, but let's try exploring the use of loops a little more.


How about printing out each digit of a number starting from its rightmost digit, going to its leftmost digit?


Instructions:

  1. Input a non-zero positive integer.
  2. Using while loop, print out each digit of the inputted integer in separate lines, starting from its rightmost digit until the leftmost digit of the number.
  3. Tip #1: Use % 10 to get the rightmost digit. For example, if you do 412 % 10, then the result would be the rightmost digit, which is 2.
  4. Tip #2: On the other hand, use / 10 to remove the rightmost digit. For example, if you do 412 / 10, then the result would be 41.
  5. Tip #3: You'd have to repeat Tip #1 and Tip #2 inside the while() loop for this problem while the inputted integer is not yet 0.

Input

A line containing an integer.

214

Output

Multiple lines containing an integer.

4
1
2





Against All "Odds"

by CodeChum Admin


Looping numbers is fun, but it's even more exciting when we combine complex tasks to it, just like looping through a series of numbers and performing a series of code only to special numbers, like odd ones! And today, we're going to do just that.

Are you ready?


Instructions:

  1. Input a positive integer. This will serve as the starting point of the loop.
  2. Using a while() loop, print out all the odd numbers starting from the inputted integer, until 0. The outputted numbers must all be separated by line.
  3. Also remember that since the loop goes to descending order, a decrement variable shall be created and decreased per iteration for the loop to terminate when it reaches 0.

Input

A line containing an integer.

10

Output

Multiple lines containing an integer.

9
7
5
3
1





Write a fruitful function sum_to(n) that returns the sum of all integer numbers up to and

including n. So sum_to(10) would be 1+2+3. . . +10 which would return the value 55.


I want very simple code because I am a student.


Write a program that reads a string and returns a table of the letters of the alphabet in

alphabetical order which occur in the string together with the number of times each letter

occurs. Case should be ignored. A sample output of the program when the user enters the data

“ThiS is String with Upper and lower case Letters”, would look this this:

a 2

c 1

d 1

e 5

g 1

h 2

I 4

l 2

n 2

o 1

p 2

r 4

s 5

t 5

u 1

w 2


I want a very simple code for students.



The great circle distance is the distance between two points on the surface of a sphere.



Let (x1, y1) and (x2, y2) be the geographical latitude and longitude of two points.



The great circle distance between the two points can be computed using the following formula:


d = radius * arccos(sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 - y2))



Write a program that prompts the user to enter the latitude and longitude of two points on the earth in degrees and displays its great circle distance.



The average earth radius is 6,371.01 km.


The angles as given in the formula are all in degrees.



Use negative values


for south and east degrees, positive values for north and west degrees.



Do all you can to make your program structure when running, conform with the sample run given below:



Enter point 1 (latitude and longitude) in degrees:


39.55, -116.25



Enter point 2 (latitude and longitude) in degrees:


41.5, 87.37



The distance between the two points is 10691.79183231593 km

LATEST TUTORIALS
APPROVED BY CLIENTS