#THIS PROGRAM COMBINES WEEKLY ASSIGNMENT 00 & 01WHICH WILL DEMONSTRATES #MY KNOWLEDEGE OF BOTH INPUT AND OUTPUT COMMANDS AS WELL AS BASIC #ARITHMETIC OPERATIONS #CIS 229 PYTHON 101 import math#LIBRARY THAT EXTENDS ESSENTIAL MATH FUNCTIONS #THE NEXT FEW LINE OF CODE ARE SUBMITTED ON THE REQUIREMENTS OF THE VECTOR PROJECT userName = raw_input("HELLO, MY NAME IS PYTHON, WHAT'S YOUR NAME?\n") print '''\tNICE NAME %s, THIS PROGRAM IS GOING TO CALCUALTE \tTHE MAGINTUDE OF TWO VECTORS. LETS GET STARTED \tFIRST I NEED YOU TO ENTER YOUR X AND Y COORDINATES\n''' % (userName) xVal, yVal = map (int,raw_input().split()) #FOUND A FUNCTION THAT WILL ALLOW ME TO READ IN TWO VALUES ON THE SAME LINE print ("THE 1ST SET (%d,%d)") % (xVal, yVal) #PRINTS THE 1ST SET OF ORDERED PAIR print("\n\tOK NOW THAT I HAVE ONE SET OF ORDER PAIRS, I NEED\nANOHTER SET. PLEASE ENTER ANOTHER SET:\n") xVal2, yVal2 = map(int, raw_input().split()) print ("THE 2ND SET (%d,%d)") % (xVal2, yVal2) #PRINTS THE 2ND SET OF ORDERED PAIR addXVal = xVal + xVal2 addYVal = yVal + yVal2 print("\nSUM OF VECTORS: (%d,%d)") % (addXVal,addYVal) #PRINTS THE SUM OF THE TWO VECTORS subXVal = xVal - xVal2 subYVal = yVal - yVal2 print("DIFFERENCE OF VECTORS: (%d,%d)") % (subXVal,subYVal) #PRINTS THE DIFFERENCE OF THE TWO VECTORS mag1 = (xVal**2) + (yVal**2) mag1 = math.sqrt(mag1) #ALLOW SIMPLE SYNTAX print("MAGINTUDE OF FIRST SET: %.3f") % (mag1) mag2 = (xVal2**2) + (yVal2**2) mag2 = math.sqrt(mag2) print("MAGINTUDE OF SECOND SET: %.3f") % (mag2)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question