Skip to content

Instantly share code, notes, and snippets.

@rishabhc32
Last active April 2, 2018 08:14
Show Gist options
  • Save rishabhc32/048ffe539a4de58fe6ca0e26b2ad53b0 to your computer and use it in GitHub Desktop.
Save rishabhc32/048ffe539a4de58fe6ca0e26b2ad53b0 to your computer and use it in GitHub Desktop.

These are my solutions, YMMV

Question 1

string = input()
upper = lower = 0
for i in string:
    if(i.isupper()):
        upper += 1
    elif(i.islower()):
        lower += 1

print('Upper: {}{}Lower: {}'.format(upper,'\n',lower))

Question 2

num_list = []

for x in range(1000, 3001):
    i = str(x)
    if (int(i[0])%2==0) and (int(i[1])%2==0) and (int(i[2])%2==0) and (int(i[3])%2==0):
        num_list.append(int(i))
    else:
        pass

print(num_list)

Question 3

ip = input()
ip = ip.split(',')
op = []
for i in ip:
    if int(i,2)%5 == 0:
        op.append(int(i))
    else:
        pass

print(op)

Question 4

import math

pos = [0,0]

while True:
	ip = input()

	if ip == 'END':
		break

	direction, step = ip.split(' ')
	step = int(step)
	
	if direction == 'UP':
		pos[1] += step
	elif direction == 'DOWN':
		pos[1] -= step
	elif direction == 'LEFT':
		pos[0] -= step
	elif direction == 'RIGHT':
		pos[0] += step

print(round(math.sqrt(pos[1]**2 + pos[0]**2)))
@rishabhc32
Copy link
Author

Comment any doubt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment