Ejemplo n.º 1
0
def fibonacci():
    num = raw_input("Enter the item Number: ")
    num = int(num)
    # num = 5
    num_index = num - 1

    first_num = 0
    second_num = 1
    fib = [first_num, second_num]

    next_num = 0

    while num <= 2:
        next_num = fib[num_index]
        # print (next_num)
        break

    for i in fib:
        ind = (j for j, x in enumerate(fib) if x == i)
        for j in ind:
            # print(i) #the number in the list
            # print(j) #the index position of the number n the list (i)
            while len(fib) - 2 < j < num_index:
                last_num = fib[j]
                # print(last_num)
                second_last_num = fib[j - 1]
                # print(last_num)
                next_num = last_num + second_last_num
                fib += [next_num]
    print(fib)
    print(next_num)
Ejemplo n.º 2
0
 def set_league_skills(self, user_input):
     header = "Please Enter the skills of the " + user_input + \
              " using the format and order below: (eg Agile Animal Clever)"
     if user_input == "leader":
         print(header)
         result = raw_input("1st_Skill 2nd_Skill 3rd_Skill \n")
     elif user_input == "sidekick":
         print(header)
         result = raw_input("1st_Skill 2nd_Skill \n")
     elif user_input == "ally":
         result = raw_input("Please Enter the level 1 or level 2 "
                            "skill for Ally: \n")
     elif user_input == "follower":
         result = raw_input("Please Enter the level 1 skill "
                            "for Follower: \n")
     print(result)
     return result.rstrip('\n')
Ejemplo n.º 3
0
from Tools.Scripts.treesync import raw_input
#from __future__ import division
__author__ = 'Ehelepola'

a=int(raw_input(""))

for i in range(0,a):
    print(pow(i,2))
Ejemplo n.º 4
0
from Tools.Scripts.treesync import raw_input

__author__ = 'luchenhua'

x = int(raw_input('Enter an integer: '))
ans = 0
while ans * ans * ans < abs(x):
    ans += 1
    print('Current guess =', ans)
if ans * ans * ans != abs(x):
    print(x, 'is not a perfect cube')
else:
    if x < 0:
        ans = -ans
    print('Cube root of ' + str(x) + ' is ' + str(ans))

x = int(raw_input('Enter an integer: '))
for ans in range(0, abs(x) + 1):
    if ans ** 3 == abs(x):
        break
if ans ** 3 != abs(x):
    print(x, 'is not a perfect cube')
else:
    if x < 0:
        ans = -ans
    print('Cube root of ' + str(x) + ' is ' + str(ans))

x = 25
epsilon = 0.01
numGuesses = 0
ans = 0.0
Ejemplo n.º 5
0
from Tools.Scripts.treesync import raw_input
#from __future__ import division
__author__ = 'Ehelepola'

a=int(raw_input(""))
b=int(raw_input(""))
c=int(raw_input(""))
print(pow(a,b))
print(pow(a,b,c))
Ejemplo n.º 6
0
"""
题目:输入某年某月某日,判断这一天是这一年的第几天?

程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊       情况,闰年且输入月份大于3时需考虑多加一天:
"""

#!/usr/bin/python
# -*- coding: UTF-8 -*-
from Tools.Scripts.treesync import raw_input

year = int(raw_input('year:\n'))
month = int(raw_input('month:\n'))
day = int(raw_input('day:\n'))

months = (0,31,59,90,120,151,181,212,243,273,304,334)
if 0 <= month <= 12:
    sum = months[month - 1]
else:
    print('data error')
sum += day
leap = 0
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
    leap = 1
if (leap == 1) and (month > 2):
    sum += 1
print( 'it is the %dth day.' % sum)
Ejemplo n.º 7
0
from Tools.Scripts.treesync import raw_input

__author__ = 'luchenhua'

x = 3
x *= x
print(x)

y = raw_input('Enter a number: ')
print(type(y))
print(y)

y = float(raw_input('Enter a number: '))
print(type(y))
print(y)
print(y * y)

x = int(raw_input('Enter an integer: '))
if x % 2 == 0:
    print('Even')
else:
    print('Odd')
if x % 3 != 0:
    print('And not divisible by 3')

x = int(raw_input('Enter x: '))
y = int(raw_input('Enter y: '))
z = int(raw_input('Enter z: '))

if x < y:
    if x < z:
Ejemplo n.º 8
0
from Tools.Scripts.treesync import raw_input

# from __future__ import division
__author__ = "Ehelepola"

firstName = raw_input("")
lastName = raw_input("")

print("Hello " + firstName + " " + lastName + "! You just delved into python.")
Ejemplo n.º 9
0
def main():
    row = 0
    col = 0

    display_mines = False
    game_state = Status.INPROGRESS

    print("!!!!!WELCOME TO THE MINESWEEPER GAME!!!!!\n")
    size = get_board_size()

    # declare 2D array of cells
    board = [[' ' for i in range(size)] for i in range(size)]

    init_board(size, board)

    # determine number of mine to place on the board
    nbr_mines = int((size * size * (get_percent_mines() / 100.0)))

    # place mines randomly on the board
    place_mines_on_board(size, board, nbr_mines)

    # For each non-mine cell, sets the neighboring mine count
    fill_in_mine_count_for_non_mine_cells(size, board)

    display_board(size, board, display_mines)

    while True:
        command = input("Enter command (m/M for command menu): ")
        if (command == "m") or (command == "M"):
            display_menu()
        elif (command == "c") or (command == "C"):
            while (row < 1) or (row > size) or (col < 1) or (col > size):
                row, col = raw_input("Enter row and col of cell: ").split()
                row, col = [int(row), int(col)]
                if (row < 1) or (row > size) or (col < 1) or (col > size):
                    print("Invalid row or column values. Try again.")
            row -= 1
            col -= 1
            game_state = select_cell(row, col, size, board)
            display_board(size, board, display_mines)
        elif (command == "s") or (command == "S"):
            display_mines = True
            display_board(size, board, display_mines)
        elif (command == "h") or (command == "H"):
            display_mines = False
            display_board(size, board, display_mines)
        elif (command == "b") or (command == "B"):
            display_board(size, board, display_mines)
        elif (command == "q") or (command == "Q"):
            print("Bye.")
            return 0
        else:
            print("Invalid command. Try again.")

        if game_state == Status.WON:
            print("You found all the mines. Congratulations. Bye.")
            return 0
        elif game_state == Status.LOST:
            print("Oops. Sorry, you landed on a mine. Bye")
            return 0
    return 0
Ejemplo n.º 10
0
from Tools.Scripts.treesync import raw_input

__author__ = 'Bartek'

while True:
    value = raw_input("Podaj wartosc: ")
    if value == "stop\n":
        break
    try:
        intValue = int(value)
    except ValueError:
        print("Wyglada na to, ze podana wartosc nie jest wartoscia typu integer!")
        continue
    print("x: " + value + "x^3: " + str(pow(intValue, 3)))
Ejemplo n.º 11
0
from Tools.Scripts.treesync import raw_input
#from __future__ import division
__author__ = 'Ehelepola'

firstName = (raw_input(""))
lastName = (raw_input(""))

print("Hello " + firstName + " " + lastName + "! You just delved into python.")