Questions: 5 831

Answers by our Experts: 5 728

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 & Filtering

Secret Message - 2

Given a string, write a program to print a secret message that replaces characters with numbers 'a' with 1, 'b' with 2, ..., 'z' with 26 where characters are separated by '-'.


You need to replace both uppercase and lowercase characters. You can ignore replacing all characters that are not letters.


abcdefghij12345678910

klmnopqr1112131415161718

stuvwxyz1920212223242526


The input will be a string in the single line containing spaces and letters (both uppercase and lowercase).Output


The output should be a single line containing the secret message. All characters in the output should be in lower case.


For example, if the given input is "python", "p" should replaced with "16", similarly"y" with "25","t" with "20","h" with "8","o" with "15","n" with "14". So the output should be "16-25-20-8-15-14".

Sample Input 1

python

Sample Output 1

16-25-20-8-15-14



Weekends

Given two dates D1 and D2, write a program to count the number of Saturdays and Sundays from D1 to D2 (including D1 and D2).

The date in string format is like "8 Feb 2021".Input


The first line of input will contain date D1 in the string format.

The second line of input will contain date D2 in the string format.Output


The output should be a single line containing two integers separated by space

Explanation


For example, if the given dates are "25 Jan 2021" and "14 Feb 2021", the Saturdays and Sundays dates from "25 Jan 2021" to "14 Feb 2021" are

"30 Jan 2021" is a Saturday

"31 Jan 2021" is a Sunday

"6 Feb 2021" is a Saturday

"7 Feb 2021" is a Sunday

"13 Feb 2021" is a Saturday

So the output should be

Saturday: 3

Sunday: 3

Sample Input 1

25 Jan 2021

14 Feb 2021

Sample Output 1

Saturday: 3

Sunday: 3

Sample Input 2

25 May 2019

22 Dec 2021

Sample Output 2

Saturday: 135

Sunday: 135



What will be the for loop of this code? and can you tell a little description of the process by mentioning what does index and len mean here! Thank you.


def f3(word, letter):

  index = 0

  while index < len(word):

    if word[index] == letter:

      return index

    index = index + 1

  return -1


print(f3("processing", "s"))

print(f3("processing", "z"))



Write a program to output the following:

  ^   ^
( o   o )
    v

Hint: Copying and pasting the code above into each line of the programming environment will help you ensure that you are accurately spacing out the required characters.




Hollow Full Pyramid - 2

Given the number of rows N, write a program to print the hallow full pyramid pattern similar to the pattern shown below.

   1 

   1 2 

  1   3 

1     4 

1 2 3 4 5


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.

.

LATEST TUTORIALS
APPROVED BY CLIENTS