Professional Documents
Culture Documents
com)
C Programming Examples
Java Algorithms
C++ Algorithms
C Algorithms
Python Program to Create a List of Tuples with the First Element as the Number and Second Element as the
Square of the Number
This is a Python Program to create a list of tuples with the first element as the number and the second element as the square of the number.
Problem Description
The program takes a range and creates a list of tuples within that range with the first element as the number and the second element as the square of the number.
Problem Solution
1. Take the upper and lower range for the numbers from the user.
2. A list of tuples must be created using list comprehension where the first element is the number within the range and the second element is the square of the number.
3. This list of tuples is then printed.
4. Exit.
Program/Source Code
Here is source code of the Python Program to create a list of tuples with the first element as the number and the second element as the square of the number. The program
output is also shown below.
Program Explanation
1. User must enter the upper and lower range for the numbers.
2. List comprehension must be used to create a list of tuples where the first number is the number itself from the given range and the second element is a square of the first
number.
3. The list of tuples which is created is printed.
Case 1:
Enter the lower range:1
Enter the upper range:4
[(1, 1), (2, 4), (3, 9), (4, 16)]
Case 2:
Enter the lower range:45
Enter the upper range:49
[(45, 2025), (46, 2116), (47, 2209), (48, 2304), (49, 2401)]
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions (http://www.sanfoundry.com/python-problems-solutions/).
Prev Page - Python Program to Generate Random Numbers from 1 to 20 and Append Them to the List (http://www.sanfoundry.com/python-program-generate-random-
numbers-append-list/)
Next Page - Python Program to Swap the First and Last Value of a List (http://www.sanfoundry.com/python-program-swap-first-last-element/)
Deep Dive @ Sanfoundry:
1. C# Programming Examples on Sorting (http://www.sanfoundry.com/csharp-programming-examples-on-sorting/)
2. C Programming Examples without using Recursion (http://www.sanfoundry.com/c-programming-examples-without-using-recursion/)
3. C Programming Examples on Bitwise Operations (http://www.sanfoundry.com/c-programming-examples-bitwise-operations/)
4. C# Programming Examples on Events (http://www.sanfoundry.com/csharp-programming-examples-on-events/)
5. C Programming Examples on Matrix (http://www.sanfoundry.com/c-programming-examples-matrix/)
6. C Programming Examples on Linked List (http://www.sanfoundry.com/c-programming-examples-linked-list/)
7. C# Programming Examples on Arrays (http://www.sanfoundry.com/csharp-programming-examples-on-arrays/)
8. Python Questions and Answers (http://www.sanfoundry.com/1000-python-questions-answers/)
9. C# Programming Examples on Matrix (http://www.sanfoundry.com/csharp-programming-examples-on-matrix/)
10. Python Programming Examples (http://www.sanfoundry.com/python-problems-solutions/)
A 26
B 11
C 6
Manish Bhojasia (http://www.sanfoundry.com/about/), a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at
Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in
Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux
Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage
Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn (http://www.linkedin.com/in/manishbhojasia) | Facebook (http://www.facebook.com/sanfoundry) | Twitter
(http://www.twitter.com/sanfoundry) | Google+ (https://plus.google.com/104408026570656234343/posts)
Name*
Email*
Subscribe
Best Careers
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in
India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro,
Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.
Best Trainings
India Internships
About Sanfoundry
About Us (http://www.sanfoundry.com/about/)
Copyright (http://www.sanfoundry.com/copyright/)
TOS & Privacy (http://www.sanfoundry.com/tos-privacy-policy/)
Jobs (http://www.sanfoundry.com/jobs/)
Bangalore Training (http://www.sanfoundry.com/coursesfees/)
Online Training (http://www.sanfoundry.com/online-training-san-linux-kernel-device-drivers/)
SAN Training (http://www.sanfoundry.com/san-storage-area-networks-training/)
Developers Track (http://www.sanfoundry.com/salary-50l/)
Mentoring Sessions (http://www.sanfoundry.com/professional-mentoring-coaching-career-guidance-cto/)
Contact Us (http://www.sanfoundry.com/contact/)
Sitemap (http://www.sanfoundry.com/sitemap_index.xml)
2011-2017 Sanfoundry