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

Develop a program to read the namebirthday and gender of a person from a file and output the name and ten-digit national identity card (NIC) number to another file where each name is starting on a new line (see the example below). The only input to the program is the name of the file. The output of the programme is the file "output.txt". Below are the rules for forming the NIC number.

  • The first four digits of the ID card is the birth year.
  • The next three digits are the number of days to the birth date from January 1st of that year. If the person is a female, 500 is added to that value.
  • The next three digits are assigned in the order of submission for a particular birth year. 
  • The input file contains the records in the order of submission where each attribute is space-separated.
  • In the example given below, Aruni is the second entry in the year 1990. Therefore the last three digits of the NIC are 002.
  • Assume there are only 999 entries per year.

Create a product class with product name, stock balance and price as attributes. include a constructer method (_init_) and also include methods for show data, issue product and get discount. Issue product must update stock balance by reducing it by a given quantity. Get discount must calculate and return 10% of price as discount. In the main program create two product objects and pass messages.


Profit or Loss

The amount at which a product is sold by the seller is known as the Selling Price. The amount at which the seller has acquired the product is known as the Cost Price.

If the Selling Price of a product is higher than its cost price, then the seller has made a profit. If it is lesser, then the seller has incurred loss selling that product. If the Selling Price is equal to the Cost Price, it means the seller has made No Profit and No loss, by selling the product.

Given Cost price

CP and selling price SP of a product, write a program to determine whether the seller made a profit, incurred loss, or made no profit or loss. Input

The first line is an integer

CP. The second line is an integer SP.Output

Print

Profit or Loss or No Profit - No Loss based on CP and SP.Explanation

In the given example,

CP = 143,SP = 155, So as the selling price is higher than the cost price, the output should be Profit.

Sample Input 1

143

155

Sample Output 1

Profit

Sample Input 2

165

125

Sample Output 2

Loss




3-digit Armstrong Number

Write a program to check if a given 3-digit number X is an Armstrong number or not.


Note: A number is an Armstrong number if the number is equal to the sum of the Nth power of its digits.


Input

The first line is an integer X.


Output

The output should be a single line containing True if it satisfies the given conditions, False in all other cases.


Explanation

In the given example X = 371,

The number of digits in 371 is 3.


So, 33 + 73 + 13 = 371. Hence, 371 is an Armstrong number.


So, the output should be True.


Sample Input 1

371

Sample Output 1

True

Sample Input 2

351

Sample Output 2

False




Write a program that prompts the user to input two POSITIVE numbers — a dividend (numerator) and a divisor (denominator). Your program should then divide the numerator by the denominator, and display the quotient followed by the remainder.

Hint: If you use division (/) to calculate the quotient, you will need to use int() to remove the decimals. You can also use integer division (// ), which was introduced in Question 10 of Lesson Practice 2.3.

Once you've calculated the quotient, you will need to use modular division (%) to calculate the remainder. Remember to clearly define the data types for all inputs in your code. You may need to use float( ) , int( ), and str( ) in your solution.

.

Give a string writen a program to return the sum and average of the number that appear in the string igonring all other characters
Give two strings write a program to determine if a string S2 is a rotation of another string S2
Do Exercise 6.4 from your textbook using recursion and the is_divisible function from Section 6.4. Your program may assume that both arguments to is_power are positive integers. Note that every positive integer that has an exponent of 0 is a power of "1". This includes "0" and "1", itself.

After writing your is_power function, include the following test cases in your script to exercise the function and print the results:

print("is_power(10, 2) returns: ", is_power(10, 2))
print("is_power(27, 3) returns: ", is_power(27, 3))
print("is_power(1, 1) returns: ", is_power(1, 1))
print("is_power(10, 1) returns: ", is_power(10, 1))
print("is_power(3, 3) returns: ", is_power(3, 3))

Write an algorithm to find the ERG character for a given employee's ERP


Armstrong numbers between two intervals
Write a program to print all the Armstrong numbers in the given range A to B(including A and B). An N-digit number is an Armstrong number if the number equals the sum of the Nth power of its digits.

Input
The first line has an integer A.
The second line has an integer B.

Output
Print all Armstrong numbers separated by a space.
If there are no Armstrong numbers in the given range, print -1.

Explanation
For A = 150 and B = 200

For example, if we take number 153, the sum of the cube of digits 1, 5, 3 is

13 + 53 + 33 = 153.

So, the output should be 153.

Sample Input 1
150
200
Sample Output 1
153
Sample Input 2
1
3
Sample Output 2
1 2 3
LATEST TUTORIALS
APPROVED BY CLIENTS