Wednesday, January 21, 2015

Learning Python - Homework 1

So I have actually decided to go back to school and get a degree in Computer Science and hopefully make myself more hire-able. One of my classes this semester is CS 1410, and I will be learning Python for this class.

I have actually taken coding classes in the past and I know my way around Java, JavaScript, and ActionScript. I have also done some stuff on my own on CodeCademy to learn those languages.

Today I turned in my first Python assignment, and I'm really excited for this class. The stuff I will post below isn't complicated at all, but at the end of the semester I will have a full game built on Python.

The assignment was basically to introduce us to Python and learn some basic syntax and make a few conversions with data that the user types on the console. If anyone has some critique, please let me know:

# Assignment001_ChristianMunoz.py
# 01/14/2014

#Function 1 = This function converts Celsius to Fahrenheit


print("This program takes a temperature in Celsius as input and converts it to Fahrenheit")


celsius = eval(input("Please input celsius to be converted:  "))


fahrenheit = 9/5 *  celsius + 32


print("The temperature is ", fahrenheit, " degrees in Fahrenheit.")

print(' ')

#Function 2 = This function converts Fahrenheit to Celsius


print("This program takes a temperature in Fahrenheit as input and converts it to Celsius")


fahrenheit = eval(input("Please input Fahrenheit to be converted:  "))


celsius = (fahrenheit - 32) * 5/9


print("The temperature is ", celsius, " degrees in Celsius.")

print(' ')

#Function 3 = This function converts Radians


print("This program takes an angle in Radians and converts it Degrees")


radians = eval(input("Please input Radians to be converted: "))


degrees = radians * (180 / math.pi)


print("The answer is ", degrees, " in Degrees")

print(' ')

#Function 4 = This function converts Degrees


print("This program takes an angle in Degrees and converts it to Radians")


degrees = eval(input("Plese input degrees to be converted: "))


radians = degrees * (math.pi / 180)


print("The answer is ", radians, " in Radians")

print(' ')

#Function 5 = This function finds two coterminal angles (one + and one -)


print("This program takes an angle in Degrees and finds two coterminal angles (one positive and one negative)")


userInput = eval(input("Please input the angle in Degrees to find coterminal angles: "))


positiveAngle = userInput + 360

negativeAngle = userInput - 360

print("The answers are: ", positiveAngle, " and ", negativeAngle, " in Degrees")

print(' ')

#Function 6 = This function finds a complement and supplement angle


print("This program takes an angle in Degrees and finds the Complement and Supplement angles")


userInput = eval(input("Please input the angle in Degrees to find the complement and supplement angles: "))


if userInput >= 180 or userInput < 0:

    complement = 'IMPOSSIBLE'
    supplement = 'IMPOSSIBLE'

    print("The Complementary angle is ", complement, " and the Supplementary angle is ", supplement, ".")

    print(' ')

elif userInput >= 90:

    complement = 'IMPOSSIBLE'
    supplement = 180 - userInput

    print("The Complementary angle is ", complement, " and the Supplementary angle is ", supplement, " in Degrees.")

    print(' ')

else:

    complement = 90  - userInput
    supplement = 180 - userInput

    print("The Complementary angle is ", complement, " and the Supplementary angle is ", supplement, " in Degrees.")

    print(' ')

That's all for now, thanks for reading!

No comments:

Post a Comment