Translate programm from Pascal to Python | Sololearn: Learn to code for FREE!

0

Translate programm from Pascal to Python

guys, need some help, I'm not good at python so I extremely indeed to translate this code to python here's code Var c : array [1..100] of longint; n, i, k, t : longint; f : text; Begin Assign(f,'keyboard.in'); Reset(f); ReadLn(f,n); For i:=1 to N do Read(f,c[i]); Readln(f,k); For i:=1 to k do begin Read(f,t); Dec(c[t]); end; Close(f); Assign(f,'keyboard.out'); Rewrite(f); For i:=1 to N do If c[i]>=0 Then Writeln(f,'no') Else Writeln(f,'yes'); Close(f); End.

2/16/2018 11:15:51 AM

JazZzik JK

2 Answers

New Answer

+2

guys, need some help, I'm not good at python so I extremely indeed to translate this code to python here's code : program bactp2018 ; uses wincrt ; type tab=array[1..100] of integer ; var n:integer ; t,c:tab ; i:integer ; function valide (x:integer ):boolean ; var i:integer ; b:boolean ; k:string ; e,d,d1:integer; begin str(x,k) ; val (k[1],d,e); val (k[2],d1,e); if( (d=6)and(d1 =6))or((d=6)and(d1=5))and(length (k)=8 )then b:=true else b:=false ; valide:=b; end ; function verif (x:integer;n:integer;t:tab):boolean; var i:integer ; b:boolean ; begin b:=false; i:=1; repeat if t[i] = x then b:= true else i:=i+1 until (b=true) or (i>n) ; end ; procedure affiche (t:tab;c:tab;n:integer ) ; var e,d,nb,i ,cmoy:integer ; p:string ; v:string ; begin cmoy:=0; nb:=0; for i :=1 to n do begin cmoy:=cmoy+c[i] ; end ; cmoy:=cmoy div n; for i:=1 to n do begin if c[i]>=cmoy then str(t[i],v); p:=copy (v,3,8); for i:= 1 to 6 do begin val(p[i],d,e); nb:=nb+ d ; end ; nb:=nb*20; writeln('le numero ',t[i],' a gagné ',nb,'dt'); end ; end ; {pg principal } begin repeat write('donner le nombre de clients:') ; readln(n) ; until n in [10..100] ; repeat write ('numero de tel du 1er clients :') ; readln(t[1]) ; until valide(t[1]) ; repeat write('montant consomme par le 1er client :'); readln(c[1]) ; until (c[1]>=0) ; for i:= 2 to n do begin repeat write('numero tel du client n°',i,':') ; readln(t[i]) ; until verif(t[i],i-1,t) and valide (t[i]) ; repeat write('montant consomme par le client n°',i) ; readln(c[i]) ; until (c[i]>=0) ; affiche(t,c,n) ; end ; end .

0

Var c : array [1..100] of longint; n, i, k, t : longint; f : text; Begin Assign(f,'keyboard.in'); Reset(f); ReadLn(f,n); For i:=1 to N do Read(f,c[i]); Readln(f,k); For i:=1 to k do begin Read(f,t); Dec(c[t]); end; Close(f); Assign(f,'keyboard.out'); Rewrite(f); For i:=1 to N do If c[i]>=0 Then Writeln(f,'no') Else Writeln(f,'yes'); Close(f); End.