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...

My First year in CSE

I always wanted to be in Computer Science. I never tried to challenge myself in this area, too. I felt like I always have this barrier not to go through it. I'm so happy that in the previous 4 months I pushed myself fast and strongly to go in this field. There is a lot of paths in front of me.  I was afraid that most of the students around me in my department have skills more than me. They are so smart and hardworking, too.  In these 4 months I've tried to:  1. get 4 stars in problem-solving on  Hackerrank 2. publish my first website on  GitHub 3. edit my account on LinkedIn 4. start my program in frontend development on Coursera 5. take more than a course on C 6. Start a course related to computer architecture.  7. Start reading about Deep Learning But, How under quarantine I could do all of that.  First of all, I knew how this is a competitive field.  1. I put a counter to know how much time I ...

My Story with Problem Solving

Hackerranck is a website full of problems that need to be solved by an algorithm or a data structure way. I knew about it while studying the Programming course at my university. The website is usable and you will like to solve on. My skills were so small and still, but I've reached 4 stars in the problem-solving path. which I'm so proud of.  I've solved 60 problems in 3 months, which is good compared to my level in programming. In my university, we learned how to code using Python 3 and I learned C, C++ on my own before. Hackerranck is consists of more than a path. There is a language path like learning Java, Ruby, Python, and so on. There is also a chapter related to data and statistics. Finally, it has a problem-solving chapter.  I think the biggest benefit I got from this experience that I don't need to fear before solving any problem also I don't mind taking more than an hour solving an easy problem. I always wanted to upgrade my way of solving, ...