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

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 '-'.


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


abcdefghij12345678910

klmnopqr1112131415161718

stuvwxyz1920212223242526Input


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.Explanation



Input 1

python

Output 1

16-25-20-8-15-14


Input2

python learning

Output 2

16-25-20-8-15-14 12-5-1-18-14-9-14-7





Numbers in String - 1

Given a string, write a program to return the sum and average of the digits of all numbers that appear in the string, ignoring all other characters.Input


The input will be a single line containing a string.Output


The output should contain the sum and average of the digits of all numbers that appear in the string.

Note: Round the average value to two decimal places.Explanation


For example, if the given string is "I am 25 years and 10 months old", the digits of all numbers that appear in the string are 2, 5, 1, 0. Your code should print the sum of all digits(8) and the average of all digits(2.0) in the new line.


Input 1

I am 25 years and 10 months old

Output 1

8

2.0


Input 2

Anjali25 is python4 Expert


Output 2

11
3.67

Given a student has scored

M marks in Maths, P marks in Physics and C marks in Chemistry. Write a program to check if a student is eligible for admission in a professional course. If any one of the below conditions is satisfied, then the student is eligible.1) M >= 70 and P >= 60 and C >= 60

2) M + P + C >= 180

Input

The first line is an integer

M, the second line is an integer P, and the third line is an integer C.Output

The output should be a single line containing

True if it satisfies the given conditions, False in all other cases.


Given N and need print the pattern given below


input:

N = 5

output :

2 6 

3 7 10

4 8 11 13

5 9 12 14 15


1. Debug(find and correct errors) and run the Python script file Lab X,
2. Analyze the output and interpret what the script is about or does[reading comments may help]
import threading
import time
def myThread():
print("Thread {} starting".format(threading.currentThread().getName()))
time.sleep(10)
print("Thread {} ending".format(threading.currentThread().getName()))
for i in range(4):

"""In the preceding code,a function myThread is defined. Within this function,
we utilize the threading.currentThread().getName()
in order to retrieve the current thread’s moniker, a
nd print this out both when we start our thread’s execution, and when it ends.
We then go on to start a for loop, and create four thread objects that take in
the name parameter, which we define as “Thread-” + str(i), as well as
the myThread function as the target of that thread’s execution.
We then, finally, go on to print out all the active threads currently running.
"""
1. Debug(find and correct errors) and run the Python script file Lab X,
2. Analyze the output and interpret what the script is about or does[reading comments may help]
import threading
import time
import random
def myThread(i):
print("Thread {}: started".format(i))
time.sleep(random.randint(1,5))
print("Thread {}: finished".format(i))
def main():
for i in range(4):
thread = threading.Thread(target=myThread, args=(i,))
thread.start()
print("Enumerating: {}".format(threading.enumerate()))
if __name__ == '__main__':
main()
"""In the preceding example, we start off by defining a function called myThread,
which will be the target of the threads that we are about to create.
Within this function, we simply print that the thread has started,
and then we wait for a random interval between 1 and 5 seconds
before printing that the thread is terminating.We have then defined a
main function which creates four distinct thread objects, and then
starts them off.

Create a GUI that allows the user to enter min/max values for Mean Motion. Make a "Find" button that when pressed has the user select an output file and finds satellites with Mean Motion within the specified range and prints them to the screen and writes them to the selected file.


Hollow Right Triangle - 2

Given an integer number 

N as input. Write a program to print the hollow right-angled triangular pattern of N lines as shown below.

Note: There is a space after each asterisk (*) character.

Input

The first line of input is an integer 

N.

Explanation

In the given example the hollow right angled triangle of side 

5. Therefore, the output should be

        *
      * *
    *   *
  *     *
* * * * *
Sample Input 1
4
Sample Output 1
      *
    * *
  *   *
* * * *
Sample Input 2
5
Sample Output 2
        *
      * *
    *   *
  *     *
* * * * *

Hollow Right Triangle

Given an integer number 

N as input. Write a program to print the hollow right-angled triangular pattern of N lines as shown below.

Note: There is a space after each asterisk (*) character.

Input

The first line of input is an integer 

N.

Explanation

In the given example the hollow right angled triangle of side 

4. Therefore, the output should be

* * * *
  *   *
    * *
      *
Sample Input 1
4
Sample Output 1
* * * * 
  *   *
    * *
      *
Sample Input 2
6
Sample Output 2
* * * * * * 
  *       *
    *     *
      *   *
        * *
          *

Perfect Squares in a Range

You are given two given numbers, 

A and B where 1 <= A <= B, Write a program to find the number of perfect squares in the range A to B (including A and B).

Input

The first line of input is an integer 

A. The second line of input is an integer B.

Explanation

In the given example, 

A = 9 and B = 100. The perfect squares in the range A to B are

3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
6 * 6 = 36
7 * 7 = 49
8 * 8 = 64
9 * 9 = 81
10 * 10 = 100

So, the output should be 

8.

Sample Input 1
9
100
Sample Output 1
8
Sample Input 2
625
1444
Sample Output 2
14
LATEST TUTORIALS
APPROVED BY CLIENTS