Friday 18 October 2019

The Joy of Computing using Python: Programming Assignment 12:

Programming Assignment-1: Holes

Let us assume paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For example letters "A", "D", "O", "P", "R" divide the plane into two regions so we say these letters each have one hole. Similarly, letter "B" has two holes and letters such as "C", "E", "F", "K" have no holes. We say that the number of holes in the text is equal to the total number of holes in the letters of the text. Write a program to determine how many holes are in a given text.

Input Format:
The only line contains a non-empty text composed only of uppercase letters of English alphabet.
Output Format:
output a single line containing the number of holes in the corresponding text.
Example-1

Input:
DRINKEATCODE

Output:
5


Explanation:
D R A O D has one hole hence total number of holes in the text is 5.
Program:

ip=input() c=0 H1=["A", "D", "O", "P", "R",'Q'] H2=["B"] #H0=['C','E','F','G','H','I','J','K','L','M','N','S','T','U','V','W','X','Y',"Z"] for i in ip: if i in H1: c+=1 elif i in H2: c=c+2 print(c,end='')

Programming Assignment-2: Smallest Palindrome


Given a string S having characters from English alphabets ['a' - 'z'] and '.' as the special character (without quotes). 
Write a program to construct the lexicographically smallest palindrome by filling each of the faded character ('.') with a lower case alphabet.

Definition:
The smallest lexicographical order is an order relation where string s is smaller than t, given the first character of s (s1 ) is smaller than the first character of t (t1 ), or in case they
are equivalent, the second character, etc.

For example "aaabbb" is smaller than "aaac" because although the first three characters
are equal, the fourth character b is smaller than the fourth character c. 

Input Format: 
String S

Output Format: 
Print lexicographically smallest palindrome after filling each '.' character, if it
possible to construct one. Print -1 otherwise.

Example-1

Input:
a.ba

Output:
abba


Example-2:

Input:
a.b

Output:
-1

Explanation: 
In example 1, you can create a palindrome by filling the '.' character by 'b'.In example 2, it is not possible to make the string s a palindrome.
Program 2:

x=list(input()) l=len(x) if l%2==1: a=x[0:int(l/2)] b=x[int(l/2)+1:] b=b[::-1] Y="alk" for i in range(len(a)): if a[i]=="." and b[i]!=".": a[i]=b[i] elif b[i]=="." and a[i]!=".": b[i]=a[i] elif a[i]=="." and b[i]==".": a[i]="a" b[i]="a" elif a[i]!=b[i] or b[i]!=a[i]: print("-1",end="") Y='fls' break if Y!="fls": b=b[::-1] s=a+["a"]+b print("".join(s),end="") else: a=x[0:int(l/2)] b=x[int(l/2):] b=b[::-1] Y="alk" for i in range(len(a)): if a[i]=="." and b[i]!=".": a[i]=b[i] elif b[i]=="." and a[i]!=".": b[i]=a[i] elif a[i]=="." and b[i]==".": a[i]="a" b[i]="a" elif a[i]!=b[i] or b[i]!=a[i]: print("-1",end="") Y='fls' break if Y!="fls": b=b[::-1] s=a+b print("".join(s),end="")


Programming Assignment-3: Letters


Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters.

Input Format:
The first line of the input contains a statement.

Output Format:
Print the number of upper case and lower case respectively separated by a space.

Example:

Input:
Hello world!

Output:
1 9
Program 3:

ip=input() up=0 lw=0 for i in ip: if i.islower() : lw+=1 elif i.isupper() : up+=1 print(up,lw,end='')

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. BookMyEssay is the right place to get the solution related to the Custom Dissertation Writing Services at reasonable price. We have best and qualified writers with us and they know the best way to complete the work within given deadlines. Have faith in our writers.

    ReplyDelete
  3. Get Installed your office Account Setup via office.com/myaccount with the help of the best experts. If the subscription has expired, learn how to renew it from here. After buying Office Product online or offline you need to visit office.com/setup to install, download and setup.

    If you're trying to find a good antivirus software that keeps all of your System safe and stable, then visit trendmicro.com/bestbuypc and will definitely help.

    Downloading Webroot antivirus by visiting at Www.webroot.com/safe. Webroot provides security for data encryption. Going through the URL on your browser will directly let you download webroot Antivirus setup.

    ReplyDelete
  4. Hi, I am John Smith I am Web Developer, It is an amazing blog thanks for the sharing the blog. Frantic infotech provide the java web development in india such as an information about software development for costumer service. Franti infotech also provide the penetration testing examples. The development of advanced web applications is Orient Software’s specialty and we will successfully fulfill all your web application development requirements, from small-sized to wider-ranged projects.

    ReplyDelete