Взятие RGB окрашивают и нормализация его с UIColor на iPhone

В вашем коде есть некоторые ошибки:

  1. Вы не указали тип ввода. Замените его на float для лучшего расчета.
  2. Вы написали неправильный синтаксис else. См. Документацию
  3. Вы неправильно вычислили площадь квадрата.

Попробуйте следующий код:

print("1 rectangle")
print("2 squared")
print("3 circle")
shape = input (">> ")

if shape == 1:
    length = float(input ("What is the length of the rectangle?"))
    breadth = float(input ("What is the breadth of the rectangle?"))
    area = length * breadth *2
    print ("the area of your rectangle", area)

elif shape == 2:
    length = float(input ("what is the length of one side of the squared"))
    area = length * length
    print ("the area of your square is ", area)

else:
    radius = float(input ("what is the radius of your circle"))
    area = radius *radius*3.14
    print ("area of your circle is ", area)

Надеюсь, что это отвечает на ваш вопрос !!!

9
задан Coocoo4Cocoa 4 May 2009 в 17:59
поделиться

1 ответ

Ваши значения находятся в диапазоне от 0 до 255. Используйте их для создания UIColor:

float r; float g; float b; float a;

[UIColor colorWithRed:r/255.f
                green:g/255.f
                 blue:b/255.f    
                alpha:a/255.f];
36
ответ дан 4 December 2019 в 06:35
поделиться