Найти - Пользователи
Полная версия: C# в python
Начало » Python для новичков » C# в python
1
vik24rus
Я только начал осваивать пайтон , помогите пожалуйста как перевести этот код в пайтоновский? До этого был знаком чуть-чуть только с С++

/*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace pacman
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
*/
using System;
using System.Threading;
namespace ConsolePacman
{
    class Program
    {
        static void Main(string[] args)
        {
            const string EdibleKeyword = "асель"; //Ключевое слово
            string pacman = ">0";
            while (true)
            {
                string input = Console.ReadLine();
                if (input.EndsWith(EdibleKeyword))
                {
                    for (int i = input.Length - 1; i >= 0; i--)
                    {
                        Thread.Sleep(250); //250мс на каждую букву
                        Console.Clear();
                        Console.WriteLine(input.Remove(i) + pacman);
                        pacman = pacman == ">0" ? "=0" : ">0";
                    }
                    Console.Clear();
                }
            }
        }
    }
}
смущает вот этот момент особо -
for (int i = input.Length - 1; i >= 0; i--) 
- как реализовать? Заранее спасибо
s0rg
import sys
import time
EdibleKeyword = 'test'
pacman = '>0'
while True:
    my_input = raw_input().strip()
    if my_input.endswith(EdibleKeyword):
        for i in xrange(len(my_input)-1, -1, -1):
            print my_input[:i] + pacman
            pacman = '=0' if pacman == '>0' else '>0'
            time.sleep(1)
Как-то так
vik24rus
СПАСИБО!!!
нашел,можно еще так
while source:
        time.sleep(0.25)
        print source + ">0"
        time.sleep(0.25)
        source = source[:-1]
        print source + "=0"

и так

import time
 
EdibleKeyword = 'ce'
source = raw_input()
if source.endswith(EdibleKeyword):
    x = 0
    while x < len(source):
        print source + ">0"
        source = source[0:len(source)-1]
        time.sleep(0.25)
        print source + "=0"
        time.sleep(0.25)
else:
    print 'Error. Try again.' 
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB