python problem

Дискусија во форумот 'Perl // Ruby // Python' започната од MeNtisH12345678, 28 Јули 2017.

  1. MeNtisH12345678

    MeNtisH12345678 n00b

    8
    2
    6 Март 2017
    Машко
    decki imam problem so kodov 2 dena ne mozam da go resam ima li nekoja hrabra dusa sto ke se obide da go resi zasto ne mi funkcionira? problemot e na kraj so definiciite xp_func(xp,p_w_att) i ogre(p_hp,xp)... znaci se raboti kako sto treba OSVEN toa sto ogre ne ja zima xp_func(p_w_att) variable da ja iskoristi vo ogre... sakam koga ke krene level 2 da dobie + 10 dmg ... ama nikako neke... castam pivo ! xD



    def vs1():
    print("")


    def vs2():
    print("")
    print("")


    def vs3():
    print("")
    print("")
    print("")


    def vs4():
    print("")
    print("")
    print("")
    print("")


    def vs5():
    print("")
    print("")
    print("")
    print("")
    print("")


    def line_func():
    print("====================================================================")

    def thin_line_func():
    print("--------------------------------------------------------------------")

    #---------------------------------------------------------------------------


    def p_w_att_func():
    p_w_att = 60 #player attack damage
    return p_w_att

    def p_w_max_hp_func():
    p_w_max_hp = 300 #player maximum hit points
    return p_w_max_hp

    #===========================================================================

    def g_att_func():
    g_att = 20 #Gnoul boss attack damage
    return g_att

    def g_max_hp_func():
    g_max_hp = 100 #Gnoul boss maximum hit points
    return g_max_hp

    #===========================================================================

    def o_att_func():
    o_att = 25 #Ogre boss attack damage
    return o_att

    def o_max_hp_func():
    o_max_hp = 800 #Ogre boss maximum hit points
    return o_max_hp

    #===========================================================================

    def g_hp_func():
    g_hp = g_max_hp_func() - p_w_att_func()
    return g_hp

    #---------------------------------------------------------------------------

    def o_hp_func():
    o_hp = o_max_hp_func() - p_w_att_func()
    return o_hp

    #---------------------------------------------------------------------------

    def p_hp_func():
    p_hp = p_w_max_hp_func() - g_att_func()
    return p_hp

    #---------------------------------------------------------------------------

    def start():
    print("=====================================================")
    print("Would you like to start? Choose with (y)yes or (n)no.\n=====================================================\n")
    while True:
    start = input("Answer: ")
    vs1()
    if start == "y" or start == "Y" or start == "yes" or start == "YES" or start == "Yes":
    start_round()
    break
    elif start == "n" or start == "N" or start == "no" or start == "NO" or start == "No":
    print("Ok see you next time... bye bye :)")
    break
    else:
    print("You have to choose with yes or no...")



    def start_round():
    p_hp = p_w_max_hp_func()
    g_hp = g_max_hp_func()
    if g_hp == g_max_hp_func():
    print("ROUND 1 - ENEMY - GNOUL BOSS")
    vs1()
    print("Gnoul boss attack damage = " + str(g_att_func()) + " | Warrior attack damage = " + str(p_w_att_func()))
    print("Gnoul boss hit points = " + str(g_hp) + " | Warrior hit points = " + str(p_hp))
    p_hp = p_hp - g_att_func()
    g_hp = g_hp - p_w_att_func()
    vs1()
    thin_line_func()
    vs1()
    print("You are now attacking the Gnoul boss.")
    vs1()
    print("You dealt " + str(p_w_att_func()) + " dmg to Gnoul boss, leaving him at " + str(g_hp) + " hp and gained " + str(p_w_att_func()) + " experience.")
    print("Gnoul boss dealt " + str(g_att_func()) + " damage to you leaving you at " + str(p_hp) + " hp.")
    vs1()
    print("You are level 1 with " + str(p_w_att_func()) + " experience!")
    vs1()
    input("continue?: ")
    vs1()
    line_func()
    gnoul()


    def gnoul():
    p_w_att = p_w_att_func()
    p_hp = p_hp_func()
    g_hp = g_hp_func()
    xp = p_w_att_func() + p_w_att_func()
    rnd = 2 # round number
    for i in range(999999):
    while g_hp > 0:
    vs1()
    print("ROUND " + str(rnd) + " - ENEMY - GNOUL BOSS")
    rnd = rnd + 1
    vs1()
    print("Gnoul boss attack damage = " + str(g_att_func()) + " | Warrior attack damage = " + str(p_w_att_func()))
    print("Gnoul boss hit points = " + str(g_hp) + " | Warrior hit points = " + str(p_hp))
    p_hp = p_hp - g_att_func()
    g_hp = g_hp - p_w_att_func()
    vs1()
    thin_line_func()
    vs1()
    print("You are now attacking the Gnoul boss.")
    vs1()
    print("You dealt " + str(p_w_att_func()) + " dmg to Gnoul boss, leaving him at " + str(g_hp) + " hp and gained " + str(p_w_att_func()) + " experience.")
    print("Gnoul boss dealt " + str(g_att_func()) + " damage to you leaving you at " + str(p_hp) + " hp.")
    vs1()
    print("You are level 1 with " + str(xp) + " experience!")
    xp = xp + p_w_att_func()
    vs1()
    input("continue?: ")
    vs1()
    line_func()
    if g_hp <= 0:
    print("CONGRATULATIONS ON YOUR FIRST VICTORY! YOUR NEXT ENEMY IS OGRE BOSS!")
    line_func()
    ogre(p_hp, xp,)


    def ogre(p_hp, xp,):
    p_w_att = p_w_att_func()
    o_hp = o_hp_func() + p_w_att_func()
    rnd = 1 # round number
    for i in range(999999):
    while o_hp > 0:
    vs1()
    print("ROUND " + str(rnd) + " - ENEMY - OGRE BOSS")
    rnd = rnd + 1
    vs1()
    print("Ogre boss attack damage = " + str(o_att_func()) + " | Warrior attack damage = " + str(p_w_att))
    print("Ogre boss hit points = " + str(o_hp) + " | Warrior hit points = " + str(p_hp))
    p_hp = p_hp - o_att_func()
    o_hp = o_hp - p_w_att
    vs1()
    thin_line_func()
    vs1()
    print("You are now attacking the Ogre boss.")
    vs1()
    print("You dealt " + str(p_w_att) + " dmg to Ogre boss, leaving him at " + str(o_hp) + " hp and gained " + str(p_w_att) + " experience.")
    print("Ogre boss dealt " + str(o_att_func()) + " damage to you leaving you at " + str(p_hp) + " hp.")
    vs1()
    #========================================================================================================================================
    xp_func(xp, p_w_att)
    xp = xp + p_w_att
    vs1()
    input("continue?: ")
    vs1()
    line_func()





    def xp_func(xp,p_w_att):
    if xp >= 0 and xp <= 150:
    print("You are level 1 with " + str(xp) + " experience!")

    elif xp >= 151 and xp <= 500:
    print("You are now level 2 with " + str(xp) + " experience!")
    p_w_att = p_w_att + 10
    print(p_w_att)


    elif xp >= 501 and xp <= 1000:
    print("You are now level 3 with " + str(xp) + " experience!")
    p_w_att = p_w_att + 10
    print(p_w_att)



    start()
     
  2. Sm0k3y25

    Sm0k3y25 Баниран/a

    416
    276
    7 ноември 2012
    Машко
    ogre(p_hp, xp,)
    def ogre(p_hp, xp,):
    Zapirkive da ne ti praat problem?
     
  3. DonFrozex

    DonFrozex Гик

    212
    149
    9 Јуни 2011
    Машко
    Да листа сега цел код и да поврзува од А до Ш што сакал да каже авторот - тешка работа дека ќе се нафати некој.

    Дај некој stack trace ако ти паѓа некаде, да видиме дали тоа ќе помогне.

    И уште едно нешто, добро намерен совет:
    Постои конвенција за пишување пајтон код, која од првин може ќќе ти изгледа болно и досадно додека и влезеш.. но ќе ти биде многу од корист кога ќе почнеш да работиш пајтон посериозно :)

    Еве ти линкче, одвој некое време, помини ја 1-2 пати..
    PEP8: The Style Guide for Python Code
     
    Последна промена: 28 Јули 2017
    На Zippo му/ѝ се допаѓа ова.
  4. MeNtisH12345678

    MeNtisH12345678 n00b

    8
    2
    6 Март 2017
    Машко
    Ne e do zapirkite smokey.. si bara tamu da si ima zapirki...sega ke go dzirnam linkceto DonFrozex... inace eve sega poskratena verzija ke stavam od kodov...
    samo copy paste codov i si raboti... e sea sakam kaj naslovot warrior attack dmg i vo sledniot del kade sto vika sega deka go pravi toj dmg... sakam dmg da napravi UPDATE vo +10 dmg odkako ke krene nad 150 experience... znaci se funkcionira osven sto ne pravi update na dmg...


    def gnoul():
    p_hp = 300
    xp = 100
    ogre(p_hp, xp)

    def ogre(p_hp, xp,):
    p_w_att = 20
    o_hp = 200 + 60
    rnd = 1 # round number
    for i in range(999999):
    while o_hp > 0:
    print("ROUND " + str(rnd) + " - ENEMY - OGRE BOSS")
    rnd = rnd + 1
    print("Ogre boss attack damage = " + str(25) + " | Warrior attack damage = " + str(p_w_att))
    print("Ogre boss hit points = " + str(o_hp) + " | Warrior hit points = " + str(p_hp))
    p_hp = p_hp - 25
    o_hp = o_hp - p_w_att
    print("==============================================")
    print("You are now attacking the Ogre boss.")
    print("You dealt " + str(p_w_att) + " dmg to Ogre boss, leaving him at " + str(o_hp) + " hp and gained " + str(p_w_att) + " experience.")
    print("Ogre boss dealt " + str(25) + " damage to you leaving you at " + str(p_hp) + " hp.")
    #========================================================
    xp_func(xp, p_w_att)
    xp = xp + p_w_att
    input("continue?: ")







    def xp_func(xp,p_w_att):
    if xp >= 0 and xp <= 150:
    print("You are level 1 with " + str(xp) + " experience!")

    elif xp >= 151 and xp <= 500:
    print("You are now level 2 with " + str(xp) + " experience!")
    p_w_att = p_w_att + 10
    print(p_w_att)


    elif xp >= 501 and xp <= 1000:
    print("You are now level 3 with " + str(xp) + " experience!")
    p_w_att = p_w_att + 10
    print(p_w_att)



    gnoul()
     
    Последна промена: 28 Јули 2017
  5. MeNtisH12345678

    MeNtisH12345678 n00b

    8
    2
    6 Март 2017
    Машко
    vidi be ne saka so indentations da ja prati porakava... inace ke vidis deka xp si pravi update ubavo koa ke krene odredeno xp da vika lvl 2 lvl 3... a dmg ne saka...
     
  6. DonFrozex

    DonFrozex Гик

    212
    149
    9 Јуни 2011
    Машко
    Пробај тука види дали ќе ти даде Indentations.

    Pastebin.com - #1 paste tool since 2002!

    one more thing.. очи болат од променливи како p_wt_o, p_at_dzm ... >/
     
  7. gdamjan

    gdamjan Ентузијаст

    2,209
    474
    3 Април 2008
    уште боље на gist.github.com
     
  8. MeNtisH12345678

    MeNtisH12345678 n00b

    8
    2
    6 Март 2017
    Машко
  9. gdamjan

    gdamjan Ентузијаст

    2,209
    474
    3 Април 2008
    па. нема некој проблем со ова. освен што тоа што корисникот го внесува
    Код:
    input("continue?: ")
    не го користиш. Кој проблем го имаш?

    пс.
    програмот го пробав со python3.6
     
  10. MeNtisH12345678

    MeNtisH12345678 n00b

    8
    2
    6 Март 2017
    Машко
    sakam update da pravi na naslovot kade sto kazuva stats gnoll i player... i kade sto kazuva player kolku dmg pravi na gnoll ... odkako ke krene 150+ xp da dobijam +10 dmg na player... i na tie stats ne im pravi update... jas vo definicijata xp_func() mu kazuvam koga ke krenes 150+ xp da vikas deka si lvl 2 i da mi krenes 10 dmg... i level 2 go kreva ama +10 dmg ne mi pravi update kade sto sakam...
     
  11. gdamjan

    gdamjan Ентузијаст

    2,209
    474
    3 Април 2008
    не гледам нигде да вика stats gnoll или stats player - така да не можам да те разберам.

    исто така, p_hp, xp, p_w_att и слично не ми кажуваат ништо, па не би можел ни да погодувам
     
  12. Zippo

    Zippo Wax on, wax off

    174
    151
    22 oктомври 2014
    Data Analyst
    Код:
    def gnoul():
      p_hp = 300
      xp = 100
      ogre(p_hp, xp)
    
    def ogre(p_hp, xp,):
      p_w_att = 20
      o_hp = 200 + 60
      rnd = 1 # round number
      while o_hp > 0:
          print("ROUND " + str(rnd) + " - ENEMY - OGRE BOSS")
          rnd = rnd + 1
          print("Ogre boss attack damage = " + str(25) + " | Warrior attack damage = " + str(p_w_att))
          print("Ogre boss hit points = " + str(o_hp) + " | Warrior hit points = " + str(p_hp))
          p_hp = p_hp - 25
          o_hp = o_hp - p_w_att
          print("==============================================")
          print("You are now attacking the Ogre boss.")
          print("You dealt " + str(p_w_att) + " dmg to Ogre boss, leaving him at " + str(o_hp) + " hp and gained " + str(p_w_att) + " experience.")
          print("Ogre boss dealt " + str(25) + " damage to you leaving you at " + str(p_hp) + " hp.")
          #========================================================
          p_w_att = xp_func(xp, p_w_att)
          xp = xp + p_w_att
          input("continue?: ")
    
    def xp_func(xp,p_w_att):
      if xp >= 0 and xp <= 150:
        print("You are level 1 with " + str(xp) + " experience!")
        return p_w_att
    
      elif xp >= 151 and xp <= 500:
        print("You are now level 2 with " + str(xp) + " experience!")
        p_w_att = p_w_att + 10
        return p_w_att
        print(p_w_att)
    
    
      elif xp >= 501 and xp <= 1000:
        print("You are now level 3 with " + str(xp) + " experience!")
        p_w_att = p_w_att + 10
        return p_w_att
        print(p_w_att)
    
    gnoul()
    1. FOR циклусот ти е апсолутно непотребен.
    2. xp_func(xp,p_w_att) не враќа што, а треба да врати

    Горниот код го решава твојот проблем.
    Намерно не правев крупни измени за да точно видиш што е променето.
     
    Последна промена: 30 Јули 2017
  13. MeNtisH12345678

    MeNtisH12345678 n00b

    8
    2
    6 Март 2017
    Машко
    zippo fala za obidot ama xp_func() vika da krene 10 dmg i da ostane na noviot dmg dodeka xp e vo radius od 150-500 xp.. vaka kako sto e ... kreva 10 dmg na sekoe continue.. :) mene samo ne mi e jasno zasto xp_func() si ja raboti rabotata vnatre vo definicijata ama neke vrednosta p_w_att da ja izvadi nadvor od definicijata i da raboti vo ogre()...
     
  14. DonFrozex

    DonFrozex Гик

    212
    149
    9 Јуни 2011
    Машко
    Да знаеш само колку лесно и брзо ќе ти беше сето ова да си го направил со класи, и да инстанцираш објекти... )
     
  15. Zippo

    Zippo Wax on, wax off

    174
    151
    22 oктомври 2014
    Data Analyst
    Ни он незнае што сака. Во тој случај:
    Код:
    def xp_func(xp,p_w_att):
      if xp >= 0 and xp <= 150:
        print("You are level 1 with " + str(xp) + " experience!")
        return p_w_att
    
      elif xp >= 151 and xp <= 500:
        print("You are now level 2 with " + str(xp) + " experience!")
        return 30
        print(p_w_att)
    
    
      elif xp >= 501 and xp <= 1000:
        print("You are now level 3 with " + str(xp) + " experience!")
        return 40
        print(p_w_att)
    
    Наместо да ти враќа функцијата инкремент, ќе ти врати точна бројка.
     
    На Fatal1ty_ му/ѝ се допаѓа ова.
  16. MeNtisH12345678

    MeNtisH12345678 n00b

    8
    2
    6 Март 2017
    Машко
    Pa toooo careee :D Ccc... Konecno nekoj da uspee :) Ti blagodaram najmnogu !
     
    На Zippo му/ѝ се допаѓа ова.
Слични теми
  1. DimeOptima
    Одговори:
    1
    Прегледи:
    989
  2. ChuleTheJudge
    Одговори:
    10
    Прегледи:
    853
  3. Nothing
    Одговори:
    2
    Прегледи:
    2,243
  4. dimitars
    Одговори:
    10
    Прегледи:
    3,172
  5. martinpk
    Одговори:
    0
    Прегледи:
    1,637
Вчитување...

Сподели