Python (Practice Test 2) With Solution (Veltech Multitech)
Python (Practice Test 2) With Solution (Veltech Multitech)
numbers form 1 to N.
Input:
First line consists of T test cases. First line of every test case consists of a
Single integer N.
Output:
Single line output, with sum of odd numbers and even numbers respectively.
Constraints:
1<=T<=100
1<=N<=10^5
--------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------
n = int(input())
list_result=[]
for i in range(0,n):
sum1 = 0
sum2 = 0
m = int(input())
for j in range(1,m+1):
if j%2==0:
sum2+=j
else:
sum1+=j
list_result.append(str(sum1)+' '+str(sum2))
for j in range(0,len(list_result)):
print(list_result[j])
Input:
The first line of input contains an integer T denoting the number of test cases.
Then T test cases follow. Each test case contains a number N as input.
Output:
For each test case, print all factorial numbers smaller than or equal to N in
new line.
Constraints:
1<=T<=100
1<=N<=1018
--------------------------------------------------------------------------------------------------------------------------------
------------------------------------
t=int(input())
while(t):
n=int(input())
fact=1
x=2
while(fact<=n):
print(fact,end=' ')
fact=fact*(x)
x=x+1
print()
t=t-1
3) Given a string S, change the string s according to the rules provided below:
INPUT: The first line consists of an integer T i.e. the number of test cases.
First and the last line of each test case consists of an string S.
CONSTRAINTS:
1<=T<=100
1<=|Length of string|<=105
--------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------
import sys
vowels= ["a", "i","e", "E", "U", "u", "o", "O", "A", "I"]
t= int(input())
for _ in range(t):
string = input()
new_string = []
for l in string:
if l not in vowels:
new_string.append(l)
b= a.swapcase()
for i in b:
print(i, end="")
print()
4) Bastin once had trouble finding number in a string. The numbers are
distributed in a string across various test cases.
There are various numbers in each test case you need to find the number in
each test case. Each test case has various numbers in sequence.You need to
find ony those numbers which do not contain 9.For eg if the string contain
"hello this is alpha 5051 and 9475".You will extract 5051 and not 9475. You
need only those numbers which are consecutive and you need to help him find
the numbers.
Note: Use long long for storing the numbers from the string.
INPUT: The first line consists of T test cases and next T lines consists of T
strings
OUTPUT: For each string output the number stored in that string if various
numbers are there print the largest one .If string has no numbers print -1.
CONSTRAINTS:
1<=T<=100
1<=|S|<=10000
--------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------
import re
t = int(input())
for a0 in range(t):
str1=input()
l = [int(i) for i in re.findall('\d+', str1) if '9' not in i]
if len(l)>0:
print (max(l))
else:
print (-1)