Skip to main content

Inputs and Outputs in Python 3

Recently, I was training on some libraries in Python 3 and I noticed that the most difficult was not the questions, but the way you are going to take your input and present your output. 
So, I'd like to show some ways I've learned and it may help you, too. 

1. Lists: 

Taking separated input like: 

2 3 4 5 6 7 and put them into the list can be done by map function: 

a = list (map(int, input().split()))
or 
a = tuple(map(int, input().split()))

same if inputs are float
- I will say that you don't need to do the same if the inputs were string! because the string is easily added into a list like: 
a = input().split() < it put them directly into a list> 
___________________________

If you'll take 2 separated numbers and you are going to use just one of them, so: 
you may use one of those ways: 
n, m = list(map(int, input().split()))
and use them by their names n, m, and so on. 
or you can use: 
p = input().split()
them if you wanna use the first number you take it as int(p[0]) 
__________________________
Arrays: 

Look at the line no.4 wt is between [] is called list comprehension (search about the syntax)
By this way, I can take inputs like the following and put it into an array (use NumPy because python doesn't support matrices) 

Sometimes, we use *map(int, input().split()) but with * and without a list when we directly put the input into a function. So, I think we use * when doing a function inside a function.
________________________

OutPuts 

I don't have any specific notices on outputs unless Formate
 "{}, Is my age".formate(age)
when age is a function when "--" is a string. we may put some details like: 
Here, we put the types and significance of the represented values. 
______________________________
One line code:
Yes, we like to write the fewest number of lines into the notepad. If we want to print more than a line of outputs, how could we achieve that? 
It is so easy use: 
sep = '\n' after putting all your printed function separated by commas, ex: 
print(n, m, k, sep = '\n')
out put = 
k
(with values of course)  
______________________________
Also a way with Numpy: 
numpy.set_printoptions(legacy='some numbers') or numpy.set_printoptions(sign='  ') 
and there are many arguments in this function. It needs to be searched. So, friends! 

I am waiting for your search results. Put the links in the comments, I'd like to check them all. 

This is the first comment from you, guys: 

Very good comments. Sometimes, I just think about the matter from the contest's view as hackerrank makes me always think.

Comments

Popular posts from this blog

Miserable

 This one word could describe my life right now. I am writing this because of the last book I read talking about how to re-organize your life. 32 days ago, my dad has gone. In the beginning, I couldn't cry. Now, I can't stop crying about everything. Everything reminds me of him. His favorite stuff became my nightmare. I dream of him every day, too. One week from his death, I took my exams. I didn't remember how I did in them. I knew they were not how I supposed to do, but I am not aware of how I did. I wish I could have cried when he passed. I wanted to cry a lot but I didn't have the ability to face myself with the fact of his death.  He died between my shoulders. I just saw his color turned to yellow like how my grandpa seemed before death. I heard my brother told him some prayers that a person says before death and I just shouted at him to stop. I spent time squeezing his feet to make him shocked. I even talked to him, I said don't go, don't leave me, not now...

Hobbies but no time!

Hi hi hi, It's been a long time since the last time here. I know I am probably not your model, besides writing my blog in English makes it not easy to scroll down.  Today I am talking about Hobbies and how to back to your hobbies while your schedule is crowded like a shit. 1. Know Your Hobbies      You need to list your favorite 10 hobbies and if you wanna try sth in the future related to this field     My 10 are [Walking, Dancing, Reading, Learning, Writing, Domino, Complete words, Sports, Problem Solving]     and I wanted to learn chess.  2. Get The Best 3 Out of Them     After listing your hobbies go rank them with stars, what your good at, and so on. Should we quiet any of the last 10? I don't think so.  3. You Just Need to Focus     I do like Dancing but I have no time to learn it. So, You put your hobbies and choose 1 or 2 to learn more about it. for example, the learnable hobbies from mine are [Dancing, Learnin...

MaharaTech: Network Course Summary

I knew it's a long time since my last post. In this post I will try to summarize most of the concepts of MaharaTech Network Course .  The Course Works for beginners and It lasts for 1 hour. If you are a beginner I tell you to plan for this course well. You should schedule 2 hours a day for 5/8 days to get the ultimate benefits of it.  There are 3 main Chapters and I will summarize them so you may return to this post in case you wanted to revise.  Introduction to Computer Networks ISO/OSI Model (7 Layers) TCP/IP Protocol Suite 1.  Introduction to Computer Networks a. Physical layer converts data from 01's to the electrical or optical or electromagnetic image.  b. Datalink layer consists of logical link control to convert, reliable, and flow the data from buckets to frames and preserve the data, resend missing messages. The other is MAC which adds the sender and receiver's physical addresses.  c. Network layer takes segments and converts them to packets. add ...