DEV Community

Cover image for TCS Quick Shots
Ranga Reddy
Ranga Reddy

Posted on

TCS Quick Shots

For the last couple of days, I am observing the question pattern in TCS. I would like to share some tricks and tips to crack the question in less time.

I hereby declare that these shots are only helpful for some type of questions in the Exam.

As of now Quick Shots are available in only Python Programming Language.

Good to Know

### Quick Inputs
name = raw_input() # for Strings
number = int(input()) # for Integers
Enter fullscreen mode Exit fullscreen mode

Yes or No Questions

def yes_or_no():
    reply = str(raw_input('(y/n):')).lower().strip()
    if reply[0] == 'y':
        return True
    if reply[0] == 'n':
        return False
    else:
        return None

isMember = yes_or_no()

if(isMember == None): 
    print("Invalid Input")
Enter fullscreen mode Exit fullscreen mode

Accepting Values in Same line (with Spaces)

values = [int(x) for x in raw_input().split()]
print(values)

# input: 1 2 3 4
# output: [1, 2, 3, 4]
Enter fullscreen mode Exit fullscreen mode

Accepting Values in Same line (with Commas)

values = [int(x) for x in raw_input().split(', ')]
print(values)

# input: 1, 2, 3, 4
# output: [1, 2, 3, 4]
Enter fullscreen mode Exit fullscreen mode

Percentage Questions

# 85% of 2043.43

def percentage(part, whole):
    return (part * whole)/100

print(percentage(85,2043.43))

# output: 1736.9155
Enter fullscreen mode Exit fullscreen mode

Invalid Input

INVALID INPUT
Note: Input and Output should be formatted as given for the example.
For any wrong value input display “INVALID INPUT”
Enter fullscreen mode Exit fullscreen mode
def inv():
    print("INVALID INPUT")

inv() 

# This helps you in code reusability 
# avoid this if have one possibility
Enter fullscreen mode Exit fullscreen mode

Float decimal value after a point

value = 3282.2548

print("%.f"%value) # 3282
print("%.1f"%value) # 3282.3
print("%.2f"%value) # 3282.25
Enter fullscreen mode Exit fullscreen mode

Stay Tuned

If you like to improve your App Development Skills, even more in Flutter and SwiftUI. Feel free to dm me on Instagram or tweet to me on Twitter if you have any additional tips or feedback.

Thanks for reading!

Top comments (2)

Collapse
 
selvakumar2012 profile image
selvakumar2012

Good

Collapse
 
irangareddy profile image
Ranga Reddy • Edited

Thanks of lot:D