Раздел форума:
Ребята, подскажите, пожалуйста, как решить задачки в программе "Питон":
1. Имеется коробка со сторонами:АхВхС. Определить, пройдет ли она в дверь с размерами МхК.
2.Значения переменных X,Y,Z поменять местами так, чтобы они оказались упорядоченными по возрастанию.
3. Дан одномерный массив числовых значений, насчитывающий N элементов. Подсчитать количество чисел делящихся на 3 и среднее арифметическое четных чисел.
4. Описать функцию Мах2(А,В) вещественного типа, находящую максимальную из двух вещественных чисел А и В. С помощью этой функции найти максимальные из пар чисел А и В,А и С, А и D, если даны числа А,В, С, D.
Я новичок в этом деле...пока сложновато!!!! Помогите, пожалуйста "чайнику".
Заранее благодарна!!!
Первую задачу не решал, там очень много рутины:), для 4-ой написал только ф-цию...(код я писал на С# и конвертировал в Питон, так что он чуть раздут :), но работает...)
2:
from System import *
class Program(object):
def Main(args):
arr = Array.CreateInstance(Double, 3)
Console.Write("X=")
arr[0] = Convert.ToDouble(Console.ReadLine())
Console.Write("Y=")
arr[1] = Convert.ToDouble(Console.ReadLine())
Console.Write("Z=")
arr[2] = Convert.ToDouble(Console.ReadLine())
Array.Sort(arr)
enumerator = arr.GetEnumerator()
while enumerator.MoveNext():
arrItem = enumerator.Current
Console.Write(arrItem.ToString() + ";")
Console.WriteLine("")
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
Main = staticmethod(Main)
3:
from System import *
class Program(object):
def Main(args):
Console.Write("N=")
N = Convert.ToInt32(Console.ReadLine())
a = Array.CreateInstance(Double, N)
i = 0
while i < N:
Console.Write("a[{0}]=", i)
a[i] = Convert.ToDouble(Console.ReadLine())
i += 1
counter2 = 0
counter3 = 0
sum = 0
enumerator = a.GetEnumerator()
while enumerator.MoveNext():
arrItem = enumerator.Current
if (arrItem % 3) == 0:
counter3 += 1
if (arrItem % 2) == 0:
counter2 += 1
sum += arrItem
Console.WriteLine("Divided into 3 = {0}", counter3)
Console.WriteLine("Average even = {0}", sum / counter2)
Console.WriteLine("")
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
Main = staticmethod(Main)
4:
def Max2(A, B):
retVal = A
if B > A:
retVal = B
return retVal
2:
from System import *
class Program(object):
def Main(args):
arr = Array.CreateInstance(Double, 3)
Console.Write("X=")
arr[0] = Convert.ToDouble(Console.ReadLine())
Console.Write("Y=")
arr[1] = Convert.ToDouble(Console.ReadLine())
Console.Write("Z=")
arr[2] = Convert.ToDouble(Console.ReadLine())
Array.Sort(arr)
enumerator = arr.GetEnumerator()
while enumerator.MoveNext():
arrItem = enumerator.Current
Console.Write(arrItem.ToString() + ";")
Console.WriteLine("")
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
Main = staticmethod(Main)
3:
from System import *
class Program(object):
def Main(args):
Console.Write("N=")
N = Convert.ToInt32(Console.ReadLine())
a = Array.CreateInstance(Double, N)
i = 0
while i < N:
Console.Write("a[{0}]=", i)
a[i] = Convert.ToDouble(Console.ReadLine())
i += 1
counter2 = 0
counter3 = 0
sum = 0
enumerator = a.GetEnumerator()
while enumerator.MoveNext():
arrItem = enumerator.Current
if (arrItem % 3) == 0:
counter3 += 1
if (arrItem % 2) == 0:
counter2 += 1
sum += arrItem
Console.WriteLine("Divided into 3 = {0}", counter3)
Console.WriteLine("Average even = {0}", sum / counter2)
Console.WriteLine("")
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
Main = staticmethod(Main)
4:
def Max2(A, B):
retVal = A
if B > A:
retVal = B
return retVal
2:
from System import *
class Program(object):
________def Main(args):
________________arr = Array.CreateInstance(Double, 3)
________________Console.Write("X=")
________________arr[0] = Convert.ToDouble(Console.ReadLine())
________________Console.Write("Y=")
________________arr[1] = Convert.ToDouble(Console.ReadLine())
________________Console.Write("Z=")
________________arr[2] = Convert.ToDouble(Console.ReadLine())
________________Array.Sort(arr)
________________enumerator = arr.GetEnumerator()
________________while enumerator.MoveNext():
________________________arrItem = enumerator.Current
________________________Console.Write(arrItem.ToString() + ";")
________________Console.WriteLine("")
________________Console.Write("Press any key to continue . . . ")
________________Console.ReadKey(True)
________Main = staticmethod(Main)
3:
from System import *
class Program(object):
________def Main(args):
________________Console.Write("N=")
________________N = Convert.ToInt32(Console.ReadLine())
________________a = Array.CreateInstance(Double, N)
________________i = 0
________________while i < N:
________________________Console.Write("a[{0}]=", i)
________________________a[i] = Convert.ToDouble(Console.ReadLine())
________________________i += 1
________________counter2 = 0
________________counter3 = 0
________________sum = 0
________________enumerator = a.GetEnumerator()
________________while enumerator.MoveNext():
________________________arrItem = enumerator.Current
________________________if (arrItem % 3) == 0:
________________________________counter3 += 1
________________________if (arrItem % 2) == 0:
________________________________counter2 += 1
________________________________sum += arrItem
________________Console.WriteLine("Divided into 3 = {0}", counter3)
________________Console.WriteLine("Average even = {0}", sum / counter2)
________________Console.WriteLine("")
________________Console.Write("Press any key to continue . . . ")
________________Console.ReadKey(True)
________Main = staticmethod(Main)
4:
def Max2(A, B):
________________retVal = A
________________if B > A:
________________________retVal = B
________________return retVal