Need Help Please

A forum for general discussion of the Python programming language.

Need Help Please

Postby jb3navides » Mon Jun 03, 2013 3:55 am

Hi everyone I am new and in dire need of help with my python code project.
There are numerous problems, hard to describe, just read and then run this python file in your terminal and you'll find alot wrong, here are some of them:
the branching paths don't work
the the else statement on some functions don't work, supposed to print invalid and restart the current function if the input was invalid but it just goes to the next function
like the input was valid
when I times a variable, I mean to times the value by 20 (1*20=20) but instead it prints the value 20 times (1*20= 11111111111111111111)
please help me and thank you to everyone in advance.
You'' have to convert the .txt file to .py and also please send me a copy of the fixed file
jb3navides@gmail.com
or at leat tell me how to fix it please.
Attachments
rcalc.txt
(8.01 KiB) Downloaded 85 times
Last edited by micseydel on Mon Jun 03, 2013 4:44 am, edited 1 time in total.
Reason: Locked OP.
jb3navides
 
Posts: 1
Joined: Mon Jun 03, 2013 1:34 am

Re: Need Help Please

Postby metulburr » Mon Jun 03, 2013 4:34 am

1) there are code tags, which allow you to input code instead of uploading a file
Code: Select all
from sys import exit
import re

def tutorial():
    print "For the meat type and doness choose between"
    print "the choices provided and type in your choice (must be exact)."
    print "For weight type the number only."

    next = raw_input("start/exit>")

    if next == "start":
        meat_type()
    elif next == "exit":
        exit(0)
    else:
        print "Invalid"
        tutorial()


def meat_type():
    global type_of_meat
    print "What type of meat are you cooking?"

    type_of_meat = raw_input("beef/lamb/venison/pork/chicken/turkey/pheasant/duck/grouse/goose>")

    if type_of_meat == "beef" or "lamb" or "venison":
        weight1()
    elif type_of_meat == "pork":
        weight2()
    elif type_of_meat == "chicken":
        weight3()
    elif type_of_meat == "turkey":
        weight4()
    elif type_of_meat == "pheasant":
        time_and_temp()
    elif type_of_meat == "duck":
        duck_type()
    elif type_of_meat == "grouse":
        time_and_temp()
    elif type_of_meat == "goose":
        time_and_temp()
    else:
        print "Invalid"
        meat_type()


def weight1():
    global weight_blv
    print "How much does your meat weigh(kg)?"

    weight_blv = raw_input(">")

    if re.match("[0-9]", weight_blv):
        doness()
    else:
        print "Invalid"
        weight1()


def weight2():
    global weight_p
    print "How much does your pork weigh(kg)?"

    weight_p = raw_input(">")

    if re.match("[0-9]", weight_p):
        time_and_temp()
    else:
        print "Invalid"
        weight2()


def weight3():
    global weight_c
    print "How much does your chicken weigh(kg)?"

    weight_c = raw_input(">")

    if re.match("[0-9]", weight_c):
        time_and_temp()
    else:
        print "Invalid"
        weight3()


def weight4():
    global weight_t
    print "How much does your turkey weigh(kg)?"

    weight_t = raw_input(">")

    if re.match("[0-9]", weight_t):
        time_and_temp()
    else:
        print "Invalid"
        weight4()


def doness():
    global doness_level
    print "To what level of \"doness\" will your meat be cooked?"

    doness_level = raw_input("rare/medium/welldone>")

    if doness_level == "rare" or "medium" or "welldone":
        time_and_temp()
    else:
        print "Invalid"
        doness()


def duck_type():
    global type_of_duck
    print "What type of duck are you cooking?"

    type_of_duck = raw_input("farmed/mallard>")

    if type_of_duck == "farmed" or "mallard":
        time_and_temp()
    else:
        print "Invalid"
        duck_type()


def time_and_temp():
    print "Here are the time/s and temperature/s needed for your meat to cook:"

    if (type_of_meat == "beef" or "lamb" or "venison") and (weight_blv <= 5) and (doness_level == "rare"):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 3) and continue to roast for"
        print weight_blv * 20
        print "minutes"
    elif (type_of_meat == "beef" or "lamb" or "venison") and (weight_blv <= 5) and (doness_level == "medium"):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 3) and continue to roast for"
        print weight_blv * 30
        print "minutes"
    elif (type_of_meat == "beef" or "lamb" or "venison") and (weight_blv <= 5) and (doness_level == "welldone"):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 3) and continue to roast for"
        print weight_blv * 40
        print "minutes"
    elif (type_of_meat == "beef" or "lamb" or "venison") and (weight_blv > 5) and (doness_level == "rare"):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 3) and continue to roast for"
        print weight_blv * 18
        print "minutes"
    elif (type_of_meat == "beef" or "lamb" or "venison") and (weight_blv > 5) and (doness_level == "medium"):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 3) and continue to roast for"
        print weight_blv * 24
        print "minutes"
    elif (type_of_meat == "beef" or "lamb" or "venison") and (weight_blv > 5) and (doness_level == "welldone"):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 3) and continue to roast for"
        print weight_blv * 36
        print "minutes"
    elif type_of_meat == "pork":
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 3) and continue to roast for"
        print weight_p * 50
        print "minutes"
    elif (type_of_meat == "chicken") and (weight_c < 2.3):
        print "Preheat oven to 210 degrees C (gas mark 6)."
        print "Roast for 20 minutes at 210 degrees C (gas mark 6)."
        print "Reduce oven temperature to 180 degrees C (gas mark 4) and continue to roast for 45 minutes"
    elif (type_of_meat == "chicken") and (weight_c >= 2.3):
        print "Preheat oven to 210 degrees C (gas mark 6)."
        print "Roast for 20 minutes at 210 degrees C (gas mark 6)."
        print "Reduce oven temperature to 180 degrees C (gas mark 4) and continue to roast for 70 minutes"
    elif (type_of_meat == "turkey") and (weight_t < 3.6):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 4) and continue to roast for 100 minutes"
    elif (type_of_meat == "turkey") and (weight_t >= 3.6):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 30 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 160 degrees C (gas mark 4) and continue to roast for 200 minutes"
    elif type_of_meat == "pheasant":
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 20 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 180 degrees C (gas mark 4) and continue to roast for 30-40 minutes"
    elif (type_of_meat == "duck") and (type_of_duck == "farmed"):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 20 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 180 degrees C (gas mark 4) and continue to roast for 60-90 minutes"
    elif (type_of_meat == "duck") and (type_of_duck == "mallard"):
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 20 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 180 degrees C (gas mark 4) and continue to roast for 35-45 minutes"
    elif type_of_meat == "grouse":
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 20 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 180 degrees C (gas mark 4) and continue to roast for 20-30 minutes"
    elif type_of_meat == "goose":
        print "Preheat oven to 220 degrees C (gas mark 7)."
        print "Roast for 20 minutes at 220 degrees C (gas mark 7)."
        print "Reduce oven temperature to 180 degrees C (gas mark 4) and continue to roast for 70-120 minutes"
    else:
        print "Invalid"
        tutorial()


tutorial()


Hi everyone I am new and in dire need of help with my python code project.
There are numerous problems, hard to describe, just read and then run this python file in your terminal and you'll find alot wrong, here are some of them:
the branching paths don't work
the the else statement on some functions don't work, supposed to print invalid and restart the current function if the input was invalid but it just goes to the next function
like the input was valid
when I times a variable, I mean to times the value by 20 (1*20=20) but instead it prints the value 20 times (1*20= 11111111111111111111)
please help me and thank you to everyone in advance.
You'' have to convert the .txt file to .py and also please send me a copy of the fixed file
jb3navides@gmail.com
or at leat tell me how to fix it please.


You'' have to convert the .txt file to .py and also please send me a copy of the fixed file

you sound more like you are demanding the fix, as you leave your email, and this statement. I think this thread will be better suited in the jobs forum, with an amount you will pay that person for the bug fix
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Need Help Please

Postby micseydel » Mon Jun 03, 2013 4:43 am

As metulburr implied, we are not going to do your work for you. Some comments to help you...
jb3navides wrote:when I times a variable, I mean to times the value by 20 (1*20=20) but instead it prints the value 20 times (1*20= 11111111111111111111)

I believe this should clarify.
Code: Select all
>>> 1 * 20
20
>>> '1' * 20
'11111111111111111111'

jb3navides wrote:
Code: Select all
if type_of_meat == "beef" or "lamb" or "venison":

This is equivalent to
Code: Select all
if (type_of_meat == "beef") or ("lamb") or ("venison"):

Since strings are evaluated as boolean True, you might as well replace this with
Code: Select all
if True:

You must check for equivalence in each expression separated by the "or" like this
Code: Select all
if type_of_meat == "beef" or type_of_meat == "lamb" or type_of_meat == "venison":

or preferably
Code: Select all
if type_of_meat in ("beef", "lamb", "venison"):

Lastly, I am not going to read your code anymore closely while you're using global variables. A function, rather than modifying a global variable when called, should return the desired value to the caller by using the return statement. If you're not sure what I mean, then Google "python functions" and try to figure it out, then come back with as specific of questions as possible.

Make sure to read this too, as it's clear you haven't yet. Programmers are forgiving people, and if you act appropriately in the future (and you have not in your original post) then you could become a valued member of this forum without anyone remembering how you got started. However, if I believe you have not read this link after I have explicitly told you to and devoted the time I have to trying to help you, you will not receive any further help from me on this problem.

EDIT: Note also that us admins can get a pretty good idea about what school you go to based on your IP address. Just so you're careful to not accidentally be perceived as academically dishonest :)
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1367
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Discussions

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests