Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6229253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:32:09+00:00 2026-05-24T09:32:09+00:00

I have created a small program to see if I’m as proficient in Python

  • 0

I have created a small program to see if I’m as proficient in Python as I am in FreeBasic (and I’m not that good with FreeBasic). Obviously, I’m asking this question because the answer is no.

So the this program is a small Dungeons and Dragons (2nd edition) combat generator. For some reason, many functions don’t execute at all. They are simply skipped over. This is what happens with attaque1(), attaque2() and most likely with calcInitiative() (since the cnt variable is not incremented at all). I tried globalizing a lot of variables thinking this might be the issue (I think all variables are globalized by default with FreeBasic). Well, this doesn’t seem to be the answer. The bug is still there and I have absolutely no idea what might cause it.

(The code has some French in it.)

#-*- coding: iso8859_1 -*-

import random

ca1 = 10
ca2 = 10
taco = 20
pv1 = random.randint(1,10)
pv1 = (pv1)
pv2 = random.randint(1,10)
pv2 = str(pv2)
cnt = 0
pv1Depart = pv1
pv2Depart = pv2
ast = "*" * 7
d20_1 = random.randint(1,20)
d8_1 = random.randint(1,8)
d20_2 = random.randint(1,20)
d8_2 = random.randint(1,8)

def intro():
    global ca1
    global ca2
    global pv1
    global pv2

    print "Imaginez deux guerriers de D&D 2e édition qui se battent."
    print
    print "Guerrier 1: " + str(pv1) + " PV, épée longue (1-8 points de dégât), TACO de 20, CA de " + str(ca1) + "."
    print "Guerrier 2: " + str(pv2) + " PV, épée longue (1-8 points de dégât), TACO de 20, CA de " + str(ca2) + "."
    print ""

def nouveauCombat():
    global cnt

    print ast + "NOUVEAU COMBAT" + ast
    print
    while ((pv1 <= 0) or (pv2 <= 0)):
        cnt = cnt + 1
        print ast + "ROUND " + str(cnt) + ast
        print
        calcInitiative()
        print
    print ast + "RESULTAT" + ast
    print
    resultat()

def calcInitiative():
    global pv1
    global pv2
    global initiative1
    global initiative2

    initiative1 = random.randint(1,10)
    initiative2 = random.randint(1,10)
    print "Le guerre 1 fait son jet d'initiative."
    print str(initiative1) + "!"
    print
    print "Le guerre 2 fait son jet d'initiative."
    print str(initiative2) + "!"
    print
    if initiative1 == initiative2:
        print "Les deux guerriers attaquent au même moment."
        print
        print ast + "ATTAQUE" + ast
        print
        attaque1()
        print
        attaque2()
    elif initiative1 < initiative2:
        print "Le guerrier 1 attaque en premier."
        print
        print ast + "ATTAQUE" + ast
        print
        attaque1()
        print
        if pv2 <= 0:
            print
            attaque2()
    else:
        print "Le guerrier 2 attaque en premier."
        print
        print ast + "ATTAQUE" + ast
        print
        attaque2()
        print
        if pv1 <= 0:
            print
            attaque2()

def attaque1():
    global d20_1
    global d8_1
    global pv2
    global ca2
    global pv2dep

    print "Le guerrier 1 fait son jet de toucher."
    print str(d20_1) + "!"
    if d20_1 >= ca2:
        print "Touché!"
        pv2 = pv2 - d8_1
        print str(d8_1) + "points de dégât!"
        print "Le guerrier 2 est à " + str(pv2) + "/" + str(pv2dep) + " PV!"
    else:
        print "Raté!"

def attaque2():
    global d20_2
    global d8_2
    global pv1
    global ca1
    global pv1dep

    print "Le guerrier 2 fait son jet de toucher."
    print str(d20_2) + "!"
    if d20_2 >= ca1:
        print "Touché!"
        pv1 = pv1 - d8_2
        print str(d8_2) + "points de dégât!"
        print "Le guerrier 1 est à " + str(pv1) + "/" + str(pv1dep) + " PV!"
    else:
        print "Raté!"

def resultat():
    global cnt

    print "Le combat prend fin au round " + str(cnt) + "."
    print 


intro()
nouveauCombat()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:32:10+00:00Added an answer on May 24, 2026 at 9:32 am

    attaque1() and attaque2() are called from calcInitiative() so if it doesn’t get called they won’t either.

    Your while loop executes while ((pv1 <= 0) or (pv2 <= 0))

    but you’ve defined them to be

    pv1 = random.randint(1,10)
    pv1 = (pv1) # this line does nothing
    pv2 = random.randint(1,10)
    pv2 = str(pv2)
    

    So neither can ever be <= 0 so the while loop will never be entered, and calcInitiative() will never be called.

    You’re writing your Python code like it were BASIC. You should go through the Python tutorial, and probably a general tutorial on object oriented programming, to learn about things like classes.

    A good test for yourself is you should be able to write that program without using globals at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a small flash CS4 project that has a few custom components
I have created a few small flash widgets that stream .mp3 audio from an
I have a program i frequently use that is made with .NET. This program
I have created a small Java application in which there is some code that
I have a small web.py Python application that I would like to serve under
I have created a small application which opens,reads and creates Excel files. The app
I want to globalize my application. I have created a small form which asks
I have a small form inside a table. POSTing that form creates a new
If I have a table like this: CREATE TABLE sizes ( name ENUM('small', 'medium',
I created a small program, as follows: #include <math.h> #include <stdio.h> #include <unistd.h> int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.