Write a python program that asks the user for a string input. This input corresponds to an attachment that changes the stats of your gun.
Attachments!
monolithic suppressor: +5 damage, -5 mobility
owc_skeleton_stock : +5 mobility, -8 Accuracy
owc_laser_tactical : +5 accuracy, +5 control
operator_foregrip : +10 control, -2 mobility
Inputs are case-insensitive. E.G. OWC Compensator == owc compensator.
P.S. No imports.
Users can be able to input multiple gun attachments by adding a semicolon; in between the attachments. There must be no whitespace present in the inputs. You might need loops to answer this question.
Print out the final stats of the gun in this format:
Man-O-War Updated Stats!
Damage: {damage}
Fire Rate: {fire rate}
Accuracy: {accuracy}
Mobility: {mobility}
Range: {shooting range}
Control: {control}
Example
User input: owc skeleton stock;owc laser tactical
Output:
Man-O-War Updated Stats!
Damage: 49
Fire Rate: 50
Accuracy: 66
Mobility: 64
Range: 56
Control: 58
Write the code to input a number and print the square root. Use the absolute value function to make sure that if the user enters a negative number, the program does not crash.
from Question #176919
REG = 'AATAA,ATTAAA,TATA,CAT,ATAGTCGC'
def find_reg(random_string_gen, reg = REG):
res = []
with open("random_string_gen.txt", 'r') as f:
text = f.read()
size = len(text) - len(reg)
for i in range(size):
for j in reg:
if text[i] != j:
break
else:
res.append([i,i+len(reg)])
file = input('Enter path and file name: ')
result = find_reg(file)
print('The pattern was found in the following positions [start, end]')
for i in result:
print(i)
what error I made
while compiling
python function3.py
The pattern was found in the following positions [start, end]
Traceback (most recent call last):
File "function3.py", line 22, in <module>
for i in result:
TypeError: 'NoneType' object is not iterable
Numbers in String - 2
Given a string, write a program to return the sum and average of the 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 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 numbers are 25, 10. Your code should print the sum of the numbers(35) and the average of the numbers(17.5) in the new line.
Sample Input 1
I am 25 years and 10 months old
Sample Output 1
35
17.5
Sample Input 2
Tech Foundation 35567
Sample Output 2
35567
35567.0
Triplet Sum
Given an array n integers, find and print all the unique triplets (a, b, c) in the array which give the sum K. (a+b+c=K).Input
The first line of the input will be space separated integers, denoting the elements of the array. The second line of the input will be an integer denoting the required sum KOutput
The output should be multiple lines, each line containing a unique triplet. The elements of the triple must be sorted in increasing order and all the triplets printed must be sorted in increasing order. Print "No Matching Triplets Found" if there are no triplets with the given sum.Explanation
Sample Input 1
0 12 17 8 9 21
29
Sample Output 1
(0, 8, 21)
(0, 12, 17)
(8, 9, 12)
Sample Input 2
0 1 2 3 5 7 13 17 19 19
22
Sample Output 2
(0, 3, 19)
(0, 5, 17)
(1, 2, 19)
(2, 3, 17)
(2, 7, 13)
The output should be printed exactly as shown in the above test cases.
Non-Adjacent Combinations of Two Words
Given a sentence as input, find all the unique combinations of two words and print the word combinations that are not adjacent in the original sentence in lexicographical order.
The input will be a single line containing a sentence.Output
The output should be multiple lines, each line containing a valid unique combination of two words. A valid combination will not contain the words that appear adjacent in the given sentence. Print "No Combinations" if there are no valid combinations_Explanation.
Sample Input 1
raju always plays cricket
Sample Output 1
always cricket
cricket raju
plays raju
Sample Input 2
python is a programming language
Sample Output 2
a language
a python
is language
is programming
language python
programming python
Sample Input 3
to be or not to be
Sample Output 3
be be
be not
or to
to to
The output should be printed exactly as shown in the above testcases.
Rotate Matrix Rings
Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.Input
The first line of input will be two space-separated integers, denoting the M and N.
The next M lines will contain N space-separated integers.
The next line will contain an integer, denoting K.Output
The output should be M*N matrix by rotating the matrix by K elements.Explanation
Sample Input 1
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
Sample Output 1
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4
Sample Input 2
3 4
1 2 3 4
10 11 12 5
9 8 7 6
2
Sample Output 2
9 10 1 2
8 11 12 3
7 6 5 4
Write a function to parse the below pattern onto a text file and highlight the matched pattern using the sliding window concept.
AATAA
ATTAAA
TATA
CAT
ATAGTCGC
Expected output
Sliding window 1: First 32 bases from 2048
TTTATGTGCCCCCCCCCATTTTATTTT
----
Till you get last 32 basesGiven a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.
Sample Input 1
4 4
1 2 3 4
5 6 7 8
7 8 9 10
11 12 13 14
3
Sample Output 1
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4
Remove Words Given a string, write a program to remove all the words with K length. Input The first line of the input will contain a string A. The second line of the input will contain an integer K. Output The output should contain a string after removing all the words whose length is equal to K. Explanation For example, string A is "Tea is good for you", k is 3 then output should be "is good." Here words "Tea", "for", "you" length is equal to 3, so these words are removed from string.