0% found this document useful (0 votes)
12 views

Python Assignment 1

Uploaded by

bhuvanagurram514
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Python Assignment 1

Uploaded by

bhuvanagurram514
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Day 1

Python
Assignments.
Assignment 1

1. Create a variable named carname and assign the value Volvo to it.

2. Display sum of 10 and 15 using two variables.

3. Insert the correct syntax to assign the same value to all three variables in one code line

X . Y . Z . “Sudheer”

4. Identify the data type


• z = -3255522
• z = -87.7e100
• x = 3+5j
• MakersLab = ("Block5",30,"IDR",True)

5. Write a code to testing if a number is even or odd


6. Write a code to solve the equation z = |x − y| * (x + y)
7. Write a code to Convert Celsius to Fahrenhit
Assignment 2
1. Write a code to display last 2 digit of a number.
2. Write a program to calculate the electricity bill according to the following criteria
Units Price

First 100 units No charge

Next 100 units Rs 5 per unit

After 200 units Rs 10 per unit

3. Write a code to print Right down mirror star Pattern


*****
****
***
**
*
4. Write a code to print Pant style pattern of stars

****************
*******__*******
******____******
*****______*****
****________****
***__________***
**____________**
*______________*

5. Write a code to print Pant style pattern of numbers

5 4 3 2 1 1 2 3 4 5

5 4 3 2 2 3 4 5

5 4 3 3 4 5

5 4 4 5

5 5
Assignment 3

1. Number guessing game


1. Write a program that chooses a random integer between 0 and 100 (inclusive).
2. Then ask the user to guess what number has been chosen.
3. Each time the user enters a guess, the program indicates one of:
1. Too high
2. Too low
3. Just right
4. If the user guessed correctly, then the program exits. Otherwise, the user is asked to
try again.
5. The program only exits after the user guesses correctly.
1. Pig Latin Translator
1. Write a Python code that takes a string as input, which would be an English word. The
function should return the translation of this word into Pig Latin. You may assume
that the word contains no capital letters or punctuation.

2. The rules for translating words from English into Pig Latin are quite simple:

1. - If the word begins with a vowel (a, e, i, o, or u), add “way” to the end of the
word. So “air” becomes “airway” and “eat” becomes “eatway.”

2. - If the word begins with any other letter, then we take the first letter, put it
on the end of the word, and then add “ay.” Thus, “python” becomes “ythonpay” and
“computer” becomes “omputercay.”
Assignment 4

1. Write a program that accepts a comma separated sequence of words as input and
prints the words in a comma-separated sequence after sorting them alphabetically.
Suppose the following input is supplied to the program:
without,hello,bag,world
Then, the output should be:
bag,hello,without,world

2.Subtract a week (7 days) from a given date in Python


3. Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional
array. The element value in the i-th row and j-th column of the array should be
i*j.
Note: i=0,1.., X-1; j=0,1,¡­
Y-1.
Example
Suppose the following inputs are given to the program:
3,5
Then, the output of the program should be:
[[0, 0, 0, 0, 0],
[0, 1, 2, 3, 4],
[0, 2, 4, 6, 8]]
4. A website requires the users to input username and password to register. Write a
program to check the validity of password input by users.
Following are the criteria for checking the password:
1. At least 1 letter between [a-z]
2. At least 1 number between [0-9]
1. At least 1 letter between [A-Z]
3. At least 1 character from [$#@]
4. Minimum length of transaction password: 6
5. Maximum length of transaction password: 12
Your program should accept a sequence of comma separated passwords and will
check them according to the above criteria. Passwords that match the criteria
are to be printed, each separated by a comma.

Example
If the following passwords are given as input to the program:
ABd1234@1,a F1#,2w3E*,2We3345
Then, the output of the program should be:
ABd1234@1
5. A robot moves in a plane starting from the original point (0,0). The robot can
move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot
movement is shown as the following:
UP 5
DOWN 3
LEFT 3
RIGHT 2
¡
The numbers after the direction are steps. Please write a program to compute the
distance from current position after a sequence of movement and original point. If
the distance is a float, then just print the nearest integer.

Example:
If the following tuples are given as input to the program:
UP 5
DOWN 3
LEFT 3
RIGHT 2
Then, the output of the program should be:
2
6. Write a program that accepts a sequence of whitespace separated words as input
and prints the words after removing all duplicate words and sorting them
alphanumerically. Suppose the following input is supplied to the program: hello
world and practice makes perfect and hello world again Then, the output should be:
again and hello makes perfect practice world

7. Calculate number of days between two given dates

You might also like