View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
For instance, in C we can do something like this:
One solution is to use raw_input[] two times.
Another solution is to use split[]
Note that we don’t have to explicitly specify split[‘ ‘] because split[] uses any whitespace characters as a delimiter as default.
One thing to note in the above Python code is, both x and y would be of string. We can convert them to int using another line
x, y = [int[x], int[y]] # We can also use list comprehension x, y = [int[x] for x in [x, y]]
Below is complete one line code to read two integer variables from standard input using split and list comprehension
x, y
=
[
int
[x]
for
x
in
input
[].split[]]
x, y
=
map
[
int
,
input
[].split[]]
This article is contributed by Abhishek Shukla. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
You can do the following if you already know the number of fields of the input:
client_name = raw_input["Enter you first and last name: "]
first_name, last_name = client_name.split[]
and in case you want to iterate through the fields separated by spaces, you can do the following:
some_input = raw_input[] # This input is the value separated by spaces
for field in some_input.split[]:
print field # this print can be replaced with any operation you'd like
# to perform on the fields.
A more generic use of the "split[]" function would be:
result_list = some_string.split[DELIMITER]
where DELIMETER is replaced with the delimiter you'd like to use as your separator, with single quotes surrounding it.
An example would be:
result_string = some_string.split['!']
The code above takes a string and separates the fields using the '!' character as a delimiter.
Write a Python program to check whether three given lengths [integers] of three sides form a right triangle. Print "Yes" if the given sides form a right triangle otherwise print "No". Input: Pictorial Presentation: Sample Solution: Python Code: Sample Output:Python Basic - 1: Exercise-34 with Solution
Integers separated by a single
space.
1 ≤ length of the side ≤ 1,000print["Input three integers[sides of a triangle]"]
int_num = list[map[int,input[].split[]]]
x,y,z = sorted[int_num]
if x**2+y**2==z**2:
print['Yes']
else:
print['No']
Input three integers[sides of a triangle] 8 6 7 No
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code [and comments] through Disqus.
Previous: Write a Python
program to compute the digit number of sum of two given integers.
Next: Write a Python program which solve the specified equation.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Python: Tips of the Day
Intersect Sets:
To get what's common in two sets:
a = {1,2,3} b = {3,4,5} c = a.intersection[b]
- Exercises: Weekly Top 16 Most Popular Topics
- SQL Exercises, Practice, Solution - JOINS
- SQL Exercises, Practice, Solution - SUBQUERIES
- JavaScript basic - Exercises, Practice, Solution
- Java Array: Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution : Conditional Statement
- HR Database - SORT FILTER: Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution : String
- Python Data Types: Dictionary - Exercises, Practice, Solution
- Python Programming Puzzles - Exercises, Practice, Solution
- C++ Array: Exercises, Practice, Solution
- JavaScript conditional statements and loops - Exercises, Practice, Solution
- C# Sharp Basic Algorithm: Exercises, Practice, Solution
- Python Lambda - Exercises, Practice, Solution
- Python Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation