This forum is in archive mode. You will not be able to post new content.

Author Topic: first python project.  (Read 4276 times)

0 Members and 1 Guest are viewing this topic.

Offline IrishYoga

  • Serf
  • *
  • Posts: 31
  • Cookies: -2
    • View Profile
first python project.
« on: January 19, 2013, 12:18:02 AM »
So i've generated my own python gpa calculator, or that's what it'll be in the end, at least. So far, all i've been able to do is bring in the raw_input from the users and make it calculate your average. But what i want to do, is get a 93, for example and make it print the gpa. How do i make python do this?

Offline hanorotu

  • Dj Rapture
  • VIP
  • Majesty
  • *
  • Posts: 1173
  • Cookies: 98
  • ( ͡° ʖ ͡°)
    • View Profile
    • Rapture
Re: first python project.
« Reply #1 on: January 19, 2013, 12:22:28 AM »
You might have to define each gpa and the associated grade and then compare it to the average


Life is hard, then you get buried.
If you want to use my work all of my music is licensed under GNU General Public License v3 (GPL-3) - http://bit.ly/TfUOBA

Offline IrishYoga

  • Serf
  • *
  • Posts: 31
  • Cookies: -2
    • View Profile
Re: first python project.
« Reply #2 on: January 19, 2013, 02:50:45 AM »
Code: [Select]
a =int (raw_input('Enter grade: '))
b =int (raw_input('Enter grade: '))
c =int (raw_input('Enter grade: '))
d =int (raw_input('Enter grade: '))
e =int (raw_input('Enter grade: '))
f =int (raw_input('Enter grade: '))
g =int (raw_input('Enter grade: '))
h =int (raw_input('Enter grade: '))
cumalitive = a,b,c,d,e,f,g,h
one = a+b+c+d+e+f+g+h
two = one/len(cumalitive)
GPA='defined'
if two<0 or two>100:
   GPA<0   


if two>=97 and two<=100:
   GPA=4.0
elif two>=93 and two<=96:
   GPA=4.0
elif two >=90 and two<=92:
   GPA=3.7
elif two>=87 and two<=89:
   GPA=3.3
elif two>=83 and two<=86:
   GPA=3.0
elif two>=80 and two<=82:
   GPA=2.7
elif two>=77 and two<=79:
   GPA=2.3
elif two>=73 and two<=76:
   GPA=2.0
elif two>=70 and two<=72:
   GPA=1.7
elif two>=67 and two<=69:
   GPA=1.3
elif two>=65 and two<=66:
   GPA=1.0
elif two<65 and two>0:
   GPA=0.0
if two>0 and two<=100 and GPA>0:
   print '\n'
   print 'your grade is'
   print two
   print 'your gpa is: '
   print GPA
else:
   print '\n'
   print 'not valid grades'






it's only able to input 8 grades right now, but i will modify it to keep adding raw_Inputs and since 'two' divides by the length of whatever the length of 'cumalitive' is, then it will be really easy.
« Last Edit: January 19, 2013, 02:56:06 AM by IrishYoga »

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: first python project.
« Reply #3 on: January 19, 2013, 05:38:31 AM »
Code: [Select]
a =int (raw_input('Enter grade: '))
b =int (raw_input('Enter grade: '))
c =int (raw_input('Enter grade: '))
d =int (raw_input('Enter grade: '))
e =int (raw_input('Enter grade: '))
f =int (raw_input('Enter grade: '))
g =int (raw_input('Enter grade: '))
h =int (raw_input('Enter grade: '))
cumalitive = a,b,c,d,e,f,g,h
one = a+b+c+d+e+f+g+h
two = one/len(cumalitive)
GPA='defined'
if two<0 or two>100:
   GPA<0   


if two>=97 and two<=100:
   GPA=4.0
elif two>=93 and two<=96:
   GPA=4.0
elif two >=90 and two<=92:
   GPA=3.7
elif two>=87 and two<=89:
   GPA=3.3
elif two>=83 and two<=86:
   GPA=3.0
elif two>=80 and two<=82:
   GPA=2.7
elif two>=77 and two<=79:
   GPA=2.3
elif two>=73 and two<=76:
   GPA=2.0
elif two>=70 and two<=72:
   GPA=1.7
elif two>=67 and two<=69:
   GPA=1.3
elif two>=65 and two<=66:
   GPA=1.0
elif two<65 and two>0:
   GPA=0.0
if two>0 and two<=100 and GPA>0:
   print '\n'
   print 'your grade is'
   print two
   print 'your gpa is: '
   print GPA
else:
   print '\n'
   print 'not valid grades'

it's only able to input 8 grades right now, but i will modify it to keep adding raw_Inputs and since 'two' divides by the length of whatever the length of 'cumalitive' is, then it will be really easy.

This is what for or while loops are for, also just store them in an list. For printing the results the %d might help.
>>>import this
-----------------------------

Offline IrishYoga

  • Serf
  • *
  • Posts: 31
  • Cookies: -2
    • View Profile
Re: first python project.
« Reply #4 on: January 19, 2013, 03:59:38 PM »
Yes i'll try to incorporate a while loop in there, but i haven't had much practice with for loops and what they can do, so i'll research that later. And i also wouldn't know how to use the %d command since all my gpa's variables are already associated with gpas

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.