Fonksiyonda kalan yerden tekrar ettirmek

Başlatan Pozitron, 09 Nisan 2015 - 15:16:22

« önceki - sonraki »

0 Üyeler ve 1 Ziyaretçi konuyu incelemekte.

Pozitron

Pythonla küçük bir oyun yazıyordum,konsol tabanlı,tamamen zevkine.Aşağıdaki
def decide_Attributes(self):
        lis=["name","health","power","intelligent","charisma"]
        for i in lis:
            if i=="name":#As you know,its type is string
                p=raw_input("Please enter your name:")
                self.player["name"]=p
            else:
                try:
                    p=int(raw_input("Please enter %s:"%(i)))#Others' types are integer
                    self.player["%s"%(i)]=p
                    dice.remove(p)
                    print "Last numbers:",dice
                except ValueError:
                    print "You don't roll this number.Try again."
                    #...
        health=self.player["health"]
        power=self.player["power"]
        intel=self.player["intelligent"]
        chari=self.player["charisma"]


Fonksiyonda kalan yeri nasıl tekrar ettiririm?Yani power sorunca yanlış girince bir daha powerı sormalı. #... olan yere ne gelmeli?
Edit:Bu arada kod alıntı değil,sadece ingilizce yazdım öylesine :)
To follow the path,look to the master,follow the master,walk with the master,see through the master,become the master.

cagriemer

Fikir vermesi adina soyle bir yontem izleyebilirsiniz. Bu yazdigim sahte kod oldugundan herhangi bir programlama dilinde calismayacaktir.


zar = rastgele.rastgeleTamSayi
cevap = okut(bir deger giriniz)
while cevap != zar
    yazdir(yanlis deger girdiniz)
    cevap = okut(bir deger giriniz)


Mutlaka daha zarif yontemleri vardir.

Pozitron

Benim istediğim şey farklı.Yani birinciyi girdin mesela sıra ikincide.İkinciyi yanlış girince başa dönmesin istiyorum.
To follow the path,look to the master,follow the master,walk with the master,see through the master,become the master.

-DıLgEş-

Alıntı yapılan: PozitronBenim istediğim şey farklı.Yani birinciyi girdin mesela sıra ikincide.İkinciyi yanlış girince başa dönmesin istiyorum.
O zaman başka bir fonksiyon oluşturup o fonksiyona yönelt. Yada gerçeği pythonda nasıl bilmiyorum ama if else komutlarıyla başka bir yere aktarabilirsin.
Aşkın; gözü kör, kulağı sağır, dili tutuk, aklı kıttır..! Hayır yani bu halde nasıl herkesi madara ediyor onu çözemedim..

Pozitron

Aynı fonksiyona geri yöneltiyorum artık yapılacak bir şey yok zaten öylesine antrenman olsun diyeydi :)
To follow the path,look to the master,follow the master,walk with the master,see through the master,become the master.

Pozitron

Uzun süre düşünmedim bu konu hakkında;fakat düşününce hemen aklıma fikir geldi;fakat fonksiyonun içinden fonksiyonu çağırmıyor. Kodun son hali şöyle:
def decide_Attributes(self,g):
        self.g=g
        lis=["name","health","power","intelligent","charisma"]
        while g!=6:
            if g==0:
               p=raw_input("Please enter your name:")
               self.player["name"]=p
               g=g+1
            else:
               p=int(raw_input("Please enter %s:"%(lis[g])))
               if not p in self.dice:
                   print "It's not in dice list.Please try again"
                   if self.remov_list!=[]:
                      self.dice=self.dice+self.remov_list
                      return decide_Attributes(g)
                   else:
                      return decide_Attributes(g)
               else:
                   self.player["%s"%(lis[g])]=p
                   self.dice.remove(p)
                   self.remov_list.append(p)
                   print "Last numbers:",self.dice
                   print self.player
To follow the path,look to the master,follow the master,walk with the master,see through the master,become the master.