2019-04-08 02:22:46 (edited by Diego 2019-04-08 02:24:29)

Hello guys!
I have two questions:
1: How can I define so that when I press a key in notepad++, the interpreter is opened and the program is executed?
2: Here is a sample code.
I would like to join the text with a variable.
print("hello!")
calc=5+10
print("the sum of 5 + 10 is" calc)

So, how to do this?

Sorry for my english

Thumbs up

2019-04-08 09:52:29

Hi there.
As I look your code, I find a error.
You should put a comma when you type "The sum of 5+10 is", so your code should be looks like that:

print("The sum of 5+10 is", calc)

If that's helpfull, why don't you press Thumbs up?

2019-04-08 18:01:51

one other question:
I installed pygame using its installer, but I do not know if it worked.
How can I check?

Thumbs up

2019-04-08 18:47:00

If you google pygame, you will find its homepage. From there you should  easily find the getting started section. There under the installation heading you will get instructions for installation as well as info on how to check if pygame is successfully installed.

You will find google and reading the documentation for whatever you are trying to use will go a long way. smile

Thumbs up

2019-04-08 21:21:58

Open python shell and type:
import pygame
If you get an error then it didn't install.
If it says hello from the Pygame comunity then it works.

My tactical battle scripts: https://www.dropbox.com/s/dzsmqv2pgqvu1 … h.zip?dl=1
Currently, one of my favorite games is Trimps.
So I'm the Trimper Trooper!

Thumbs up

2019-04-08 22:40:13

Hello guys!
I'm trying to install pygame from python shell, but it does not install.
Anyone have any tips?
I have python 3.7.3

Thumbs up

2019-04-09 01:18:25

Type "pip3 install pygame" on the command line. Then in the python shell type:

import pygame
pygame.version.ver

That should tell you the pygame version, if installed correctly. Note that python IDLE doesn't play nice with screen readers, but you can use any text editor and save a script as a plain text document with a *.py prefix, then run it on the command line with "python yourscript.py". Here's a simple pygame example to help you get started:

import pygame
from pygame import mixer
import sys

def Example():
#initialize pygame
    pygame.init()
#initialize sound mixer
    mixer.init()
#create display
    window = pygame.display.set_mode([640,480])
#load sound
    sound = mixer.Sound('tone5.wav')

#main update loop
    while True:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
            #if space is pressed, play sound
                if event.key == pygame.K_SPACE:
                    sound.play()
            #if escape is pressed, quit
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit(0)

    #update window
        pygame.display.update()

Example()
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

Thumbs up

2019-04-09 02:05:30

thank you!
it's working!

Thumbs up

2019-04-09 02:12:22

is there any way to, when I'm programming in notepad ++ and want to run the code in python, I press a key and it does?
I tried to search but the solution I found did not work

Thumbs up

2019-04-12 21:09:15

Hello guys!

Two more questions:
1: I installed visual studio 2019 code, python 3.7 and python extension.
When I try to run some code, it does not show the python interpreter in the list that opens.
How to correct this?
2: When writing some program even with errors, it simply closes not showing the error, this happens in the python shell.
What to do so that instead of closing the program it shows the error?

Thumbs up

2019-04-13 00:39:03

@10, your second question has a solution but it is a bit advanced. Here's how you do that though:
The sys function has a variable, excepthook, which defines what the application will do when an exception is thrown and not caught by any try blocks in the program. As with anything in Python bar tuples, this particular value is mutable. The function looks like this:
excepthook(exctype, value, traceback)
That means that, should you modify this variable to point to another function, it must follow a similar signature: it must take only the parameters in the function above. The parameters mean the following:
* exctype: the type of exception being thrown. This can be something like KeyboardInterrupt, which is not an exception that you should treat as an actual error, or it can be an actual exception, such as ValueError, SyntaxError, UnboundLocalError, and so on. (Yes, the syntax error messages you get are, in fact, exceptions in Python. I would not, however, ignore them.)
* value: The instance of this exception. Use this when reporting errors; it will contain the actual message of the exception.
* traceback: the tracebak (in full). You may also use this, if you like, though beware that it will reveal code lines. Its very useful in debugging your code, but not very useful in release builds.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-04-17 04:36:45

Hello guys!
I am trying to play a sound automatically and when I press enter it stops.  What I was able to do was reproduce the sound, but every key that I pressed it playdd the sound again.
Anyone have any tips? I followed the help of post 7.

Thumbs up

2019-04-17 06:23:40

The example provided should only play the sound when the space bar is pressed. If you've altered the code for another purpose, it would help to share that code to better troubleshoot the issue.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

Thumbs up

2019-04-18 00:01:19

import pygame   
from pygame import mixer
import sys
def intro():
    pygame.init()
    mixer.init()
window = pygame.display.set_mode([800, 400])
pygame.mixer.init(44100, -16,2,2048)
sound = pygame.mixer.Sound('sons\intro.ogg')
while True:
    for event in pygame.event.get():
        sound.play()
if event.type == pygame.KEYDOWN:
    if event.key == pygame.K_ENTER:
        sound.stop()
    if event.key == pygame.K_ESCAPE:
        pygame.quit()
sys.exit(0)
pygame.display.update()
intro()

Thumbs up

2019-04-18 00:39:57

When you way you want the sound to play automatically, under what circumstances do you want it to play? As the code is written, whenever the main loop checks for an event it will play the sound. Judging by the name of the sound file is it safe to assume your trying to set up a skippable intro? There are a few ways to write that, but in this case you may want to start playing the sound outside the primary loop so it won't start playing again, like so:

...
sound = pygame.mixer.Sound('sons\intro.ogg')
sound.play()
while True:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ENTER:
                sound.stop()
...
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

Thumbs up