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 a Python program to establish a database connection to EmpDB and display the total gross salary paid to the employee working in the Quality Control Department. Assume the employee table has already been created and exists in the EmpDB. The fields of the Employee table are (EmpID, DeptName, GrossSalary).
. Consider the loop from Section 8.3 of your textbook.

prefixes = 'JKLMNOPQ'
suffix = 'ack'

for letter in prefixes:
print(letter + suffix)

Put this code into a Python script and run it. Notice that it prints the names "Oack" and "Qack".

Modify the program so that it prints "Ouack" and "Quack" but leaves the other names the same.

Include the modified Python code and the output in your submission.

2. Give at least three examples that show different features of string slices. Describe the feature illustrated by each example. Invent your own examples. Do not copy them for the textbook or any other source.

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

"14 Feb 2021" is a Sunday

So the output should be

Saturday: 3

Sunday: 3

Sample Input 1

25 May 2019
22 Dec 2021

Sample Output 1

Saturday: 135
Sunday: 135

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

stuvwxyz1920212223242526

Output

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

Explanation

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

Sample Input 2

Foundations

Sample Output 2

6-15-21-14-4-1-20-9-15-14-19
Exercise 8.4 from your textbook. Each of the following Python functions is supposed to check whether its argument has any lowercase letters.

For each function, describe what it actually does when called with a string argument. If it does not correctly check for lowercase letters, give an example argument that produces incorrect results, and describe why the result is incorrect.

# 1

def any_lowercase1(s):
for c in s:
if c.islower():
return True
else:
return False


# 2

def any_lowercase2(s):
for c in s:
if 'c'.islower():
return 'True'
else:
return 'False


# 5

def any_lowercase5(s):
for c in s:
if not c.islower():
return False
return True
Exercise 8.4 from your textbook. Each of the following Python functions is supposed to check whether its argument has any lowercase letters.

For each function, describe what it actually does when called with a string argument. If it does not correctly check for lowercase letters, give an example argument that produces incorrect results, and describe why the result is incorrect.

# 1

def any_lowercase1(s):
for c in s:
if c.islower():
return True
else:
return False


# 2

def any_lowercase2(s):
for c in s:
if 'c'.islower():
return 'True'
else:
return 'False'


# 3

def any_lowercase3(s):
for c in s:
flag = c.islower()
return flag


# 4

def any_lowercase4(s):
flag = False
for c in s:
flag = flag or c.islower()
return flag

add two polynomials given two polynomials a and b, write a program that adds the given two polynomials a and b. input the first line contains a single integer m. next m lines contain two integers pi, ci separated with space, where pi denotes power and ci denotes co-efficient of pi for polynomial a. after that next line contains a single integer n. next n lines contain two integers pj, cj separated with space, where pj denotes power and cj denotes co-efficient of pj for polynomial b.

Please help me for this i am not able to do this


3. Disarium Number


A number is said to be Disarium if the sum of its digits raised to their respective positions is the number itself.


Example:

75

7^1+5^2=7+25=32 → False


135

1^1+3^2+5^3=1^9+125=135 → True


Print True if a number is a Disarium, otherwise print False.



Input

The Input will be any integer


135



Output


True


add two polynomials given two polynomials a and b, write a program that adds the given two polynomials a and b. input the first line contains a single integer m. next m lines contain two integers pi, ci separated with space, where pi denotes power and ci denotes co-efficient of pi for polynomial a. after that next line contains a single integer n. next n lines contain two integers pj, cj separated with space, where pj denotes power and cj denotes co-efficient of pj for polynomial b.

How to print 0 in the code for this question since i am trying this question from last 1 mnth i am not passing test casses please help me to do this


Develop a program to read the name, birthday and gender of a person from a file and output the name and ten-digit identity card (NIC) number to another file , each name starting on new line (see
example below)The only input to the program is the name of the file. output is the file "output.txt".
rules
The first 4 digits of the ID card is the birth year.
The next 3 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 to submission for a particular birth year. input file contains the records of submission where each attribute is space separated.
In example , Aruni is the second entry in year 1990. Therefore the last three digits of NIC are 002.Assume there are only 999 entries per year.
Example:
Input file output file
Saman 1990-05-03 M Saman 1990123001
Aruni 1990-04-06 F Aruni 1990596002
Nazar 1997-09-24 M Nazar 1997267001
LATEST TUTORIALS
APPROVED BY CLIENTS