Another beautiful day in this miserable world

Python Programming


#A certain CS professor gives 5-point quizzes that are graded on the scale
#5-A, 4-B, 3-C, 2-D, 1-F, 0-F. Wirte a program that accepts a quiz score
#as an input and prints out the corresponding grade.
def main():
    grade = eval(input("What is your quiz score? (Type quit to stop) "))
        if grade == 5:
            letter = 'A'
        if grade == 4:
            letter = 'B'
        if grade == 3:
            letter = 'C'
        if grade == 2:
            letter = 'D'
        if grade == 1 or grade == 0:
            letter = 'F'
        print(" Your grade is a ", letter)
main()


#Write a program to sum a series of numbers entered by the user.
#The program should first prompt the use for how many numbers are to be summer.
#It should then input each of the numbers and print a total sum.

def main():
    total = 0
    num = eval(input("How many numbers do you have? "))
    for i in range (num):
        ber = eval(input("What is your first number? "))
        total = ber + total

    print("The total value of your ", num, "numbers is ", total)

main()

I was lamenting (which I obviously do a lot) about stuff and wrote a facebook status – written below. One of my friends mentioned that it was a recurrence relation that should be tested which I immediately took as a challenge and coded it. This was what I needed after struggling to understand Java syntax which is something I find to be an extreme opposite of Python.

Status:
Completely lost trying to program because I have to miss class because I have to go to work because I have to make money because I have to pay for college because I have to pay for class that I have to miss because I have to go to work because I have to make money because I have to pay for college because I have to pay for class that I have to miss because I have to go to work because I….need a vacation….


def func (var):
    if var == "I have to miss class":
        return 1
    if var == "I have to go to work":
        return 2
    if var == "I have to make money":
        return 3
    if var == "I have to pay for college":
        return 4
    if var == "I have to pay for class":
        return 5
    
def status(variable):
    if variable == 5:
        return 1
    else:
        return (variable + 1)
    
def twice(var):
    if var == 1:
        return "I have to miss class"
    if var == 2:
        return "I have to go to work"
    if var == 3:
        return "I have to make money"
    if var == 4:
        return "I have to pay for college"
    if var == 5:
        return "I have to pay for class"

    
def main():
    variable = 1
    while 1>0:
        variable = input("Completely lost in programming because ")
        because = func(variable)
        recur = status(because)
        reverse = twice(recur)
        print(variable, "because", reverse)
        
main()

This came to me around 3 in the morning while I was sitting on my 9th hour straight doing a programming for class lamenting about my canceled plans for the evening and lack of sleep for the week. Some of these are obviously not said by me (or anybody else I hope), but you would be surprised what pops into your head after 3 days of no sleep and enough energy drinks to sink a small country in Africa.

DISCLAIMER***This is mean to be for humorous purposes only so don’t get your panties in a bunch if you feel the need to get offended by things that may or may not pertain to you. if(you == f*cking idiot troll) { return GTFO and die; }

To a Significant Other:

“I made you dinner, I hope you like it”
Translation: I hope you don’t mind it’s a little bit salty. I needed something to cover up the Nyquil I mixed in there so you’ll go to sleep and I won’t be obligated to give you attention tonight.”

“Ok I’ll take a break and we can spend some time together”
Translation: You may think you have my full attention, but while you’re catterwalling about things not related to my program, I’m thinking of ways to make my program better and will most likely sneak a few lines of code in while you’re going to the bathroom.

“I love you”
Translation: Almost as much as I love my program.

“Honey, can you pick up the kids today?”
Translation: The only reason I remember that I have children is because I program I have it in bold letters on my google calender and I assume that since they aren’t here they need picking up. We have kids right?

“Nothing is wrong, my program just won’t run.”
Translation: You have absolutely no idea that my whole world is crashing down around my ankles and you will never understand.

To Friends:

“Yeah, I’ll be there as soon as I’m done writing this program.”
Translation: Call me a ditcher because not only am I not getting there any time this century, but I’ll probably be so worked up over perfecting the unperfectable that I’ll put our friendship on the back burner.

“You’re my best friend”
Translation: I like you so much that I use your name as variables.

“I had fun last night, we should hang out again soon at my place.”
Translation: Last night was OK, but just wait until you come over. I have 21 computers hooked to 49 monitors and OMG we will have a f*cking BLAST compiling and resolving syntax errors.

“I’m not doing much tonight, just going to stay in and relax.”
Translation: I’m going to sit on my ass and play WOW (or other obsessive game) and masturbate about 5 times.

To Random People:

“I’m a programmer”
Translation: I’m just letting you know why I’m going to treat you like the obvious lower intelligence in this conversation.

“Excuse me”
Translation: I have more important things to do in my life than to wait for a lower life form to get out of my way.

To Other Programmers:

“I really like your program, Good Job!”
Translation: I’m just sucking up so you’ll lower your guard for a little bit so that I can go and make a bigger and better program than you just made and rub it in your face.

“Do you know how to do this?”
Translation: I actually know how to do this, but I’m seeing if you know how to do this so I can keep track on how far ahead of you I am.

“We should hang out sometime”
Translation: I haven’t had a chance to flex my mental muscles in front of you and doing it in public will make your defeat even sweeter.

“Sure I can do that for you”
Translation: I’m going to wait until you’ve asked me for this at least 20 times then put together the worst possible thing I can so you’ll look bad and give you all the credit for it.

To Yourself:

“I just need to run this code to make sure it works and then I’m done.”
Translation: Theres a 241.7% chance that 1/3 of my syntax was fat fingered and for each error it’ll take me about 20 read-throughs of the program before I finally catch what’s wrong so don’t plan on bothering me for the next 2 days unless you come with redbull and pizza.”

“I’m going to bed”
Translation: There’s no translation for this because “bed” doesn’t compute in programming language.

“I’m hungry”
Translation: My adderol wore off and I’m starting to feel the pains for not eating for 3 days. Must order pizza.

“I’m tired”
Translation: Let me chase this adderol with a 5 hour energy shot and compliment it with a redbull.

This was a Comp Sci homework assignment to have a user input 5 grades from their classes and it would calculate the GPA. There were to be no loops, so alot of the code is redundant I know. Took me all of 15 hours to do. Python > Java.

*Netbeans IDE


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;


/**
 *
 * @author Cori
 */

public class Main {

    /**
     * @param args the command line arguments
     */
    public static double gpapts(String grade) {
        double pts = 0.00;
        if ("A".equals(grade)) {
            pts = (4.00);
        } else if ("A-".equals(grade)) {
            pts = 3.67;
        } else if ("B+".equals(grade)) {
            pts = 3.33;
        } else if ("B".equals(grade)) {
            pts = 3.00;
        } else if ("B-".equals(grade)) {
            pts = 2.67;
        } else if ("C+".equals(grade)) {
            pts = 2.33;
        } else if ("C".equals(grade)) {
            pts = 2.00;
        } else if ("C-".equals(grade)) {
            pts = 1.67;
        } else if ("D+".equals(grade)) {
            pts = 1.33;
        } else if ("D".equals(grade)) {
            pts = 1.00;
        } else if ("F".equals(grade)) {
            pts = 0.0;
        } else {
                System.out.println("Error"); System.out.print("-1.0"); System.exit(0);
        } 
        return pts;

    }
    public static void main(String[] args) {
       
        
        java.util.Scanner input = new java.util.Scanner(System.in);

        System.out.print("How many credits was your first class ");
        int class1 = input.nextInt(); input.nextLine();
        System.out.print("What grade did you get? ");
        String ans1 = input.nextLine();
        String grade1 = ans1.toUpperCase();
        double pts1 = gpapts(grade1);
        double cg1 = class1 * pts1;
        System.out.print("How many credits was your second class? ");
        int class2 = input.nextInt(); input.nextLine();
        System.out.print("What grade did you get? ");
        String ans2 = input.nextLine();
        String grade2 = ans2.toUpperCase();
        double pts2 = gpapts(grade2);
        double cg2 = class2 * pts2;
        System.out.print("How many credits was your third class? ");
        int class3 = input.nextInt(); input.nextLine();
        System.out.print("What grade did you get? ");
        String ans3 = input.nextLine();
        String grade3 = ans3.toUpperCase();
        double pts3 = gpapts(grade3);
        double cg3 = class3 * pts3;
        System.out.print("How many credits was your fourth class? ");
        int class4 = input.nextInt(); input.nextLine();
        System.out.print("What grade did you get? ");
        String ans4 = input.nextLine();
        String grade4 = ans4.toUpperCase();
        double pts4 = gpapts(grade4);
        double cg4 = class4 * pts4;
        System.out.print("How many credits was your fifth class? ");
        int class5 = input.nextInt(); input.nextLine();
        System.out.print("What grade did you get? ");
        String ans5 = input.nextLine();
        String grade5 = ans5.toUpperCase();
        double pts5 = gpapts(grade5);
        double cg5 = class5 * pts5;
        int clavg = class1+class2+class3+class4+class5;
        double gravg = cg1+cg2+cg3+cg4+cg5;
        double avg = gravg/clavg;
        if (avg == 4.00) {
            System.out.printf("Your GPA is %.2f \n", avg);
            System.out.print("You have made the President's List!");
        }
        else if (avg < 4.00) {
            if (avg >= 3.50) {
                System.out.printf("Your GPA is %.2f \n", avg);
                System.out.print("You have made the Dean's List!");
            }
                if (avg >= 2.00) {
                    if (avg < 3.50) {
                    System.out.printf("Your GPA is %.2f", avg);
                }
            }

            else if (avg < 2.00) {
                System.out.printf("Your GPA is %.2f \n", avg);
                System.out.print("You are on academic probation :'(");
            
        }
    }

}
}

Sorry guys :(

Sorry for the lack of posts. With class starting, I haven’t had much time other than work and school. My new class focuses on Java, so my next few posts will most likely be on those. I hope to get back to Python soon, Java sucks :)

12. Write a program to find the sum of the cubes of the first n natural numbers where the value of n is provided by the user


def main():
    print("This program finds the sum of the cubes of the first ")
    print("'n' natural numbers starting with 0")
    n = eval(input("Enter any natural number "))
    add = 0
    for i in range (n):
        add = add + i**3
    print(add)
main()

11. Write a program to find the sum of the first n natural numbers where the value of n is provided by the user.

def main():
    print("This program finds the sum of the first 'n' natural numbers")
    print("starting with 0")
    n = eval(input("Enter any natural number "))
    add = 0
    for i in range (n):
        add = add + i
    print(add)
main()

10. Write a program to determine the length of a ladder required to reach a given height when leaned against a house. Prompt for an angle in degrees and convert it to radians.


from math import *
def main():
    height = eval(input("Please enter the height of the ladder "))
    deg = eval(input("Please enter the angle of the ladder in degrees "))
    rad = (pi/180) * deg
    leng = height/(sin(rad))
    print("The length of the ladder must be ", leng)
main()

9. Write a program to calculate the area of a triangle given the length of its three sides a,b, and c.

We will have to change the formula given in the book a little bit due to Python not recognizing a number outside of a parenthesis as multiplying. We will need to insert the “*” to get the program to work correctly.

from math import *
def main():
    a,b,c = eval(input("Enter the length of each side of a triangle seperated by commas "))
    s = (a+b+c)/2
    a = sqrt(s*(s-a)*(s-b)*(s-c))
    print("The area of the triangle is", a)
main()

Tag Cloud

Follow

Get every new post delivered to your Inbox.