Jump to content
Slark

Ajutor Python

Recommended Posts

sa zicem ca am facut in python sa apara in Command Prompt (Windows)

o mapa de genu

##############

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

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

#--------J--------#

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

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

##############

iar acum eu vreau sa misc J de la tastatura cu W A S D

care ii comanda sa citeasca ce apas la tastatura?

sau nu exista asa ceva in (cmd)

stiu ca in c++ era

folosesc python 3.5.0

m-am uitat pe google dar nu am gasit mare lucru

decat msvcrt.getch() dar nu imi dau seama cum functioneaza

Link to comment
Share on other sites

  • Active Members

Python nu are implicit functionalitatea asta. Pe Windows poti folosi modulul msvcrt:


import msvcrt

print 'Press a,s,d or w to move the object:\n'
input_char = msvcrt.getch()

if input_char == 'a':
print 'Aici muti elementul la stanga' # faci asa si pentru restu' controalelor

Link to comment
Share on other sites

imi poate explica cineva de ce apare cu b?

sau care ii faza cu el?

Python 3 https://docs.python.org/3.3/reference/lexical_analysis.html#string-literals

Bytes literals are always prefixed with 'b' or 'B'; they produce an instance of the bytes type instead of the str type. They may only contain ASCII characters; bytes with a numeric value of 128 or greater must be expressed with escapes.

Python 2 https://docs.python.org/2/reference/lexical_analysis.html#string-literals

A prefix of 'b' or 'B' is ignored in Python 2; it indicates that the literal should become a bytes literal in Python 3 (e.g. when code is automatically converted with 2to3). A 'u' or 'b' prefix may be followed by an 'r' prefix.
Link to comment
Share on other sites

  • Active Members
Mersi mult MrGrj

nu a mers exact cum ai scris tu

dar mi-am dat seama unde era buba

if input_char == b'a':

trebuie sa pun inainte de 'a' (sau 'w', 's', 'd') cate un b

imi poate explica cineva de ce apare cu b?

sau care ii faza cu el?

Caracterul tau ( `a` ) trebuie tratat ca un byte string(asa trebuie), de aici si sintaxa:

b'char'

Edited by MrGrj
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...