Wednesday, 2 October 2019

The Joy of Computing using Python: Programming Assignment: 1,2 and 3:

Programming Assignment-1: Counter Spiral


Given a square matrix, you have to write a program to print it in a counter-clockwise spiral form.


Input Format:
The first line of the input contains an integer number n which represents the number of rows and columns in the matrix.
From the second line contains n rows with each row having n elements separated by a space.

Output Format:
Print the elements in a single line with each element separated by a space

Example:

Input:
4
25 1 29 7
24 20 4 32
16 38 29 1
48 25 21 19

Output:
25 24 16 48 25 21 19 1 32 7 29 1 20 38 29 4

Explanation: 
In the above example, each row, first all the elements of the first column is printed which are 25 24 16 48 after that, remaining elements of the last row is printed which are 25 21 and 19.
After which the remaining elements of the last column is printed which are 1 32 and 7 and so on...

a = int(input()) mat=[] for i in range(0,a): l = list(map(int, input ().split ())) mat.append(l) m=a n=a k = 0 l = 0 count = 0 total = a*a while (k < m and l < n) : if (count == total) : break for i in range(k, m) : print(mat[i][l], end = " ") count += 1 l += 1 if (count == total) : break for i in range (l, n) : print( mat[m - 1][i], end = " ") count += 1 m -= 1 if (count == total) : break if (k < m) : for i in range(m - 1, k - 1, -1) : print(mat[i][n - 1], end = " ") count += 1 n -= 1 if (count == total) : break if (l < n) : for i in range(n - 1, l - 1, -1) : print( mat[k][i], end = " ") count += 1 k += 1



Programming Assignment-2: Maximum Numeric


Given an alphanumeric string S, extract maximum numeric value from that string. All the alphabets are in lower case. Take the maximum consecutive digits as a single number.

Input Format:
The first line contains the string S.

Output Format:
Print the maximum value

Example:
Input:
23dsa43dsa98

Output:
98

Explanation:
There are three integer values present in the string, 23, 43 and 98. Among these, 98 is the maximum.

import re ip=input() l=((re.findall('\d+', ip))) l=list(map(int,l)) print(max(l),end='')



Programming Assignment-3: Email ID


Assuming that we have some email addresses in the "username@companyname.com" format, please write program to print the company name of a given email address. Both user names and company names are composed of letters only.

Input Format:
The first line of the input contains an email address.

Output Format:
Print the company name in single line.

Example;

Input:
john@google.com

Output:
google

Program: 

ip=input() x=ip.index("@") print(ip[x+1:len(ip)-4],end='')

2 comments:

  1. Digital circuits assignment 9 please sir ?

    ReplyDelete
  2. Digital marketing assignments please

    ReplyDelete