尝试使用from random import randint
def playGame()
while pipisuyu == 1:
secim = input("Taas kagit....")
AI = randint(0, 2)
if secim == "Tas" and AI == 0:
print ("Rakibiniz de Tas secti, berabere!")
elif secim == "Tas" and AI == 1:
print ("Rakibiniz kagit secmisti. Kaybettin!")
pipisuyu -= 1
elif secim == "Tas" and AI == 2:
print ("Rakibiniz makas secmisti. Kazandiniz!")
pipisuyu -= 1
elif secim == "Kagit" and AI == 0:
print ("Rakibiniz tas secmisti. Kazandiniz!")
pipisuyu -= 1
elif secim == "Kagit" and AI == 1:
print ("Rakibiniz de kagit secmisti. Berabere!")
elif secim == "Kagit" and AI == 2:
print ("Rakibiniz makas secmisti. Kaybettiniz!")
pipisuyu -= 1
elif secim == "Makas" and AI == 0:
print ("Rakibiniz tas secmisti. Kaybettiniz!")
pipisuyu -= 1
elif secim == "Makas" and AI == 1:
print ("Rakibiniz kagit secmisti. Kazandiniz!")
pipisuyu -= 1
elif secim == "Makas" and AI == 2:
print ("Rakibiniz de makas secmisti. Berabere!")
while True:
playGame()
创建地方实例,但收到以下错误:
FactoryGirl.create(:place)
无法弄清楚原因,因为在我的工厂里我明确设置了town_city:
放置工厂:
Failure/Error: FactoryGirl.create(:place)
ActiveRecord::StatementInvalid:
PG::NotNullViolation: ERROR: null value in column "town_city" violates not-null constraint
DETAIL: Failing row contains (1, 2017-07-14 13:32:41.246627, 2017-07-14 13:32:41.246627, 51.476900, 0.000010, Greenwich Observatory, Greenwich, London, null, 24849 Lesch Garden, null, null, null, MF4 1FO, null, null, null, null, 1, null, f).
: INSERT INTO "places" ("created_at", "geocode_address", "latitude", "longitude", "postcode", "region_id", "street_address", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"
# ./spec/requests/api/v1/events_spec.rb:5:in `block (2 levels) in <top (required)>'
Page&amp;可分页特征:
factory :place, traits: [:pageable] do
town_city 'my hardcoded value'
latitude { rand(50.0...53.0) }
longitude { rand(-2.0...2.0) }
street_address { Faker::Address.street_address }
postcode { Faker::AddressUK.postcode }
association :region, factory: :region
end
区:
trait :pageable do
association :page, strategy: :build
end
factory :page do
sequence(:title) { |n| "#{Faker::Product.product_name}-#{n}" }
association :user
association :cover_image, factory: :image
telephone { Faker::PhoneNumber.phone_number }
description { generate :paragraphs_seq }
end
任何想法可能是什么原因?
答案 0 :(得分:1)
事实证明,我的Place模型中有 before_validation 挂钩,试图使用Region字段数据重置 town_city 。所以我想我必须修改我的地区工厂